- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkedList.py
More file actions
Latest commit
38 lines (33 loc) · 828 Bytes
/
Copy pathLinkedList.py
File metadata and controls
38 lines (33 loc) · 828 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
# A single node of a singly linked list
#LinkedList
classNode:
# constructor
def__init__(self, data=None, next=None):
self.data=data
self.next=next
# A Linked List class with a single head node
classLinkedList:
def__init__(self):
self.head=None
# insertion method for the linked list
definsert(self, data):
newNode=Node(data)
if(self.head):
current=self.head
while(current.next):
current=current.next
current.next=newNode
else:
self.head=newNode
# print method for the linked list
defprintLL(self):
current=self.head
while(current):
print(current.data)
current=current.next
# Singly Linked List with insertion and print methods
LL=LinkedList()
LL.insert(3)
LL.insert(4)
LL.insert(5)
LL.printLL()