1. class Node:
2. def __init__(self,value):
3. self.data = value
4. self.next = 0
5.
6. class List:
7. def __init__(self):
8. self.firstNode = Node(0)
9.
10. def __ShowNodeData(self,aNode):
11. if aNode.next != 0:
12. print aNode.data
13. self.__ShowNodeData(aNode.next)
14.
15. def Dump(self):
16. self.__ShowNodeData(self.firstNode)
17.
18. def InsertAfter(self,aNode,aNewNode):
19. aNewNode.next = aNode.next
20. aNode.next = aNewNode
21.
22. def InsertBeginning(self,aNewNode):
23. aNewNode.next = self.firstNode
24. self.firstNode = aNewNode
25.
26. nodeA = Node("A")
27. nodeB = Node("B")
28. nodeC = Node("C")
29. nodeD = Node("D")
30.
31. aList = List()
32.
33. aList.InsertBeginning(nodeB)
34. aList.InsertAfter(nodeB,nodeD)
35. aList.InsertAfter(nodeD,nodeC)
36. aList.InsertAfter(nodeC,nodeA)
37.
38. aList.Dump()
No comments:
Post a Comment