-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.py
More file actions
67 lines (56 loc) · 1.45 KB
/
linkedlist.py
File metadata and controls
67 lines (56 loc) · 1.45 KB
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
59
60
61
62
63
64
65
66
67
class Node:
def __init__(self, data=None):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def printing(self):
printvalue = self.head
while printvalue is not None:
print(printvalue.data)
printvalue = printvalue.next
def beg(self, data3):
new = Node(data3)
new.next = self.head
self.head = new
def end(self, data4):
new = Node(data4)
if self.head is None:
self.head = new
return
lastNode = self.head
while(lastNode.next):
lastNode = lastNode.next
lastNode.next = new
def between(self, node, datapart):
new = Node(datapart)
new.next = node.next
node.next = new
def delNode(self,deldata):
new = self.head
if new is not None:
if new.data == deldata:
self.head = new.next
new = None
return
while new is not None:
if new.data == deldata:
break
prev = new
new = new.next
if (new == None):
return
prev.next = new.next
new = None
x = LinkedList()
x.head = Node("mohmmad")
data1 = Node("mohammadi")
data2 = Node("iran")
x.head.next = data1
data1.next = data2
x.beg("sara")
x.end("jafar")
x.between(x.head,"between")
x.delNode("mohammadi")
x.printing()