-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedList.py
More file actions
49 lines (35 loc) · 906 Bytes
/
Copy pathlinkedList.py
File metadata and controls
49 lines (35 loc) · 906 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
47
48
49
# https://www.geeksforgeeks.org/linked-list-set-1-introduction/
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def printData(self):
temp = self.head
while(temp):
print(str(temp.data)+"--->",end="")
temp = temp.next
print("")
def pushToFront(self,data):
new_node = Node(data)
new_node.next = self.head
self.head = new_node
def pushToBack(self,data):
new_node = Node(data)
temp = self.head
while(temp.next):
temp = temp.next
temp.next = new_node
ll = LinkedList()
ll.head = Node(1)
second = Node(2)
third = Node(3)
ll.head.next = second
second.next = third
ll.printData()
ll.pushToFront(10)
ll.printData()
ll.pushToBack(11)
ll.printData()