-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_linked_list.py
More file actions
46 lines (35 loc) · 847 Bytes
/
Copy path01_linked_list.py
File metadata and controls
46 lines (35 loc) · 847 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
43
44
45
46
# sinlge link list implementation in python
class node:
__data = None
__nxtptr = None
def __init__(self):
self.__data = None
self.__nxtptr = None
def setval(self, val):
self.__data = val
def setnxt(self, nxt):
self.__nxtptr = nxt
def getnxt(self):
return self.__nxtptr
def getval(self):
return self.__data
def insert_at_start(h, val):
temp = node()
temp.setnxt(None)
temp.setval(val)
if h == None:
h = temp
else:
temp.setnxt(h)
h = temp
return h
def display(h):
cur = node
cur = h
while cur != None:
print(cur.getval())
cur = cur.getnxt()
head = None
for _ in range(5):
head = insert_at_start(head, 5)
display(head)