-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinked Lists.py
58 lines (45 loc) · 1.53 KB
/
Linked Lists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Node:
def __init__(self, data = -1, node = None):
self.data = data
self.next = node
def update_data(self, data):
self.data = data
def display(node):
if node is not None:
temp = node.next
print("List :")
while temp is not None:
print("->", temp.data),
temp = temp.next
else:
print("List is EMPTY! Try adding a few nodes first.")
def main():
print("Menu:\n1.New List\t2.Add a node at the head.\n3. Add a node at the end.\n4.Delete a node given the data.")
print("\n5. Delete a node at the head.\t6. Delete a node at the end.\n7.Print the list.\n8. BREAK!")
print("\nNote: This program is for a single linked list, singly linked or doubly linked.")
print("Enter you choice:")
choice = int(input())
node = Node()
while choice != 8:
if choice == 1:
node = Node(int(input("Enter data :")), None)
print("Node list created. Node.data=", node.data)
elif choice == 2:
if node is not None:
temp = Node(int(input("Enter data : ")),node.next)
node.next = temp
else:
print("List is EMPTY! Try adding a few nodes first.")
elif choice == 3:
print()
elif choice == 4:
print()
elif choice == 5:
print()
elif choice == 6:
print()
elif choice == 7:
display(node)
print("Enter your choice:")
choice = int(input())
main()