-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.py
More file actions
33 lines (28 loc) · 840 Bytes
/
linked_list.py
File metadata and controls
33 lines (28 loc) · 840 Bytes
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
class Node:
def __init__(self,data):
self.data = data
self.next = None
self.prev = None
def get_data(self):
return self.data
class LinkedList():
def __init__(self):
self.head = None
def get_last_node(self):
temp = self.head
while(temp.next != None):
temp = temp.next
return temp
def add_node(self,data):
if self.head == None:
self.head = Node(data)
else:
last_node = self.get_last_node()
last_node.next = Node(data)
last_node.next.prev = last_node
def print_nodes(self):
temp = self.head
counter = 1
while(temp != None):
print(f"{counter}.Node.data = {temp.data}")
temp = temp.next