kopia lustrzana https://github.com/animator/learn-python
rodzic
b2a1669105
commit
d2a25f16cc
|
@ -104,28 +104,27 @@ Lets complete the code and create a linked list.
|
||||||
|
|
||||||
Connect all the code.
|
Connect all the code.
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
llist = LinkedList()
|
llist = LinkedList()
|
||||||
|
|
||||||
# Insert words at the beginning
|
# Insert words at the beginning
|
||||||
llist.insertAtBeginning(4) # <4>
|
llist.insertAtBeginning(4) # <4>
|
||||||
llist.insertAtBeginning(3) # <3> 4
|
llist.insertAtBeginning(3) # <3> 4
|
||||||
llist.insertAtBeginning(2) # <2> 3 4
|
llist.insertAtBeginning(2) # <2> 3 4
|
||||||
llist.insertAtBeginning(1) # <1> 2 3 4
|
llist.insertAtBeginning(1) # <1> 2 3 4
|
||||||
|
|
||||||
# Insert a word at the end
|
# Insert a word at the end
|
||||||
llist.insertAtEnd(10) # 1 2 3 4 <10>
|
llist.insertAtEnd(10) # 1 2 3 4 <10>
|
||||||
llist.insertAtEnd(7) # 1 2 3 4 10 <7>
|
llist.insertAtEnd(7) # 1 2 3 4 10 <7>
|
||||||
|
|
||||||
#Insert at a random position
|
#Insert at a random position
|
||||||
llist.insertAtPosition(9,4) ## 1 2 3 <9> 4 10 7
|
llist.insertAtPosition(9,4) ## 1 2 3 <9> 4 10 7
|
||||||
# Print the list
|
# Print the list
|
||||||
llist.printList()
|
llist.printList()
|
||||||
|
|
||||||
|
|
||||||
|
## output:
|
||||||
output:
|
1 2 3 9 4 10 7
|
||||||
1 2 3 9 4 10 7
|
|
||||||
|
|
||||||
|
|
||||||
### Deleting a node from the beginning of a linked list
|
### Deleting a node from the beginning of a linked list
|
||||||
|
|
Ładowanie…
Reference in New Issue