-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linked_List.py
55 lines (38 loc) · 1021 Bytes
/
Linked_List.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
from LinkedListNode import LinkedListNode
class LinkedList(object):
def __init__(self, head):
self.head =head
def getHead(self):
return self.head
def setHead(self, head):
self.head= head
def insertFirst(self, LLNode):
if self.getHead() == None:
self.head = LLNode
# print ("There is no head")
head.setNext(None)
else:
LLNode.setNext(self.head)
# print ("Setting the head")
tail = self.head
self.head = LLNode
def insertLast(self, LLnode):
tail.setNext(LLNode)
tail = LLNode
tail.setNext(None)
def deleteFirst(self):
temp = self.head
self.head = temp.getNext()
return temp #insert the first, and then delete first into the json.
def query(self, data):
current = head
while(current != None):
if current.getData() == data:
return current
return None
def insertAfter(self, node, data):
LLNode = LinkedListNode(data)
lLNode.setNext(node.getNext().getNext())
node.setNext(lLNode)
if node == head:
lLNode = tail