class Node: def __init__(self): self.data = None # contains the data self.nextNode = None # contains the reference to the next node # create a linked list without a cycle head = Node() head.data = 0 current = head for i in range(1,9): new_node = Node() new_node.data = i current.nextNode = new_node current = new_node def printList(head): current = head while current.nextNode: print current.data current = current.nextNode print current.data printList(head)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question