forked from Purusottamdas/HacktoberFest2020-1
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkedList.py
More file actions
44 lines (38 loc) · 1.04 KB
/
LinkedList.py
File metadata and controls
44 lines (38 loc) · 1.04 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
class node:
def __init__(self,data):
self.data=data
self.next=None;
class LinkedList:
def __init__(self):
self.start=None;
def viewList(self):
if self.start==None:
print("list is empty")
else:
temp=self.start
while temp!=None:
print(temp.data,end= ' ')
temp=temp.next
def deleteFirst(self):
if self.start==None:
print("Linked list is empty")
else:
self.start=self.start.next
def insertLast(self,value):
newNode=node(value)
if(self.start==None):
self.start=newNode;
else:
temp=self.start
while temp.next!=None:
temp=temp.next
temp.next=newNode
mylist=LinkedList()
mylist.insertLast(20)
mylist.insertLast(30)
mylist.insertLast(40)
mylist.insertLast(50)
mylist.insertLast(60)
mylist.viewList()
mylist.deleteFirst()
mylist.viewList()