Difference between revisions of "NodeLoop.py"

From WLCS
(Created page with "<syntaxhighlight lang="Python"> class Node: def __init__(self): self.data = 0 self.next = None n1 = Node() #create and connect several Nodes n1.data = 5...")
 
(No difference)

Latest revision as of 22:20, 17 October 2013

class Node:
    def __init__(self):
        self.data = 0
        self.next = None


n1 = Node()     #create and connect several Nodes
n1.data = 5
n1.next = Node()
n1.next.data = 3
n2 = Node()
n1.next.next = n2
n2.data = 8

current = n1     #start a reference at n1
while current != None:     #loop while the current reference is not None
    print(current.data)     #print the data at the current Node
    current = current.next     #update the current reference to go to the next Node