-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdouble_linked_list.py
More file actions
42 lines (34 loc) · 881 Bytes
/
double_linked_list.py
File metadata and controls
42 lines (34 loc) · 881 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
34
35
36
37
38
39
40
41
42
class node:
def __init__(self, data=None):
self.next = None
self.data = data
class linked_list:
def __init__(self):
self.head = node()
def append(self, data):
new_node = node(data)
current = self.head
while(current.next != None):
current = current.next
current.next = new_node
def display(self):
display_vals = []
current = self.head
while(current.next != None):
current = current.next
display_vals.append(current.data)
print(display_vals)
def length(self):
count = 0
current = self.head
while(current.next != None):
count += 1
current = current.next
print(count)
ll = linked_list()
ll.append(4)
ll.append(3)
ll.append(5)
ll.append(11)
ll.display()
ll.length()