Skip to content
Snippets Groups Projects
Select Git revision
  • 2c584fc7e951aa6181ff0f5f25ad78cefbda6142
  • master default protected
2 results

liste-liee.py

Blame
  • liste-liee.py 811 B
    class Node:
        def __init__(self, data = None, next = None):
            self.data = data
            self.next = next
    
    class LinkedList:
        def __init__(self):
            self.head = None
    
        def listprint(self):
            printval = self.head
            while printval is not None:
                print(printval.dataval)
                printval = printval.nextval
        
        def push(self, n):
            if self.head is None:
                self.head = Node(n)
            else:
                node = self.head
                while node.next is not None:
                    node = node.next
                node.next = Node(n)
    
        def detectLoop(self):
            s = set() 
            temp = self.head 
            while (temp):
                if (temp in s): 
                    return True
                s.add(temp) 
                temp = temp.next
            return False