Skip to content

Commit 31a73b4

Browse files
Update singly_LinkedList.py
1 parent 3ee70b3 commit 31a73b4

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

data_structures/LinkedList/singly_LinkedList.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
1-
class Node: #create a Node
1+
class Node:#create a Node
22
def __int__(self,data):
3-
self.data=data #given data
4-
self.next=None #given next to None
3+
self.data=data#given data
4+
self.next=None#given next to None
55

66
class Linked_List:
77
pass
8-
def insert_tail(Head,data): #insert the data at tail
9-
tamp=Head #create a tamp as a head
10-
if(tamp==None): # if linkedlist is empty
11-
newNod=Node() #create newNode Node type and given data and next
8+
def insert_tail(Head,data):#insert the data at tail
9+
tamp=Head#create a tamp as a head
10+
if(tamp==None):#if linkedlist is empty
11+
newNod=Node()#create newNode Node type and given data and next
1212
newNod.data=data
1313
newNod.next=None
1414
Head=newNod
1515
else:
16-
while tamp.next!=None: #find the last Node
16+
while tamp.next!=None:#find the last Node
1717
tamp=tamp.next
18-
newNod = Node() #create a new node
18+
newNod = Node()#create a new node
1919
newNod.data = data
2020
newNod.next = None
21-
tamp.next=newNod #put the newnode into last node
22-
return Head #return first node of linked list
21+
tamp.next=newNod#put the newnode into last node
22+
return Head#return first node of linked list
2323

2424
def insert_head(Head,data):
2525
tamp = Head
2626
if (tamp == None):
27-
newNod = Node() #create a new Node
27+
newNod = Node()#create a new Node
2828
newNod.data = data
2929
newNod.next = None
30-
Head = newNod #make new node to Head
30+
Head = newNod#make new node to Head
3131
else:
3232
newNod = Node()
3333
newNod.data = data
34-
newNod.next = Head #put the Head at NewNode Next
35-
Head=newNod # make a NewNode to Head
34+
newNod.next = Head#put the Head at NewNode Next
35+
Head=newNod#make a NewNode to Head
3636
return Head
37-
38-
def Print(Head): #print every node data
37+
38+
def Print(Head):#print every node data
3939
tamp=Node()
4040
tamp=Head
4141
while tamp!=None:
4242
print(tamp.data)
4343
tamp=tamp.next
4444

45-
def delete_head(Head): #delete from head
45+
def delete_head(Head):#delete from head
4646
if Head!=None:
4747
Head=Head.next
48-
return Head #return new Head
48+
return Head#return new Head
4949

50-
def delete_tail(Head): #delete from tail
50+
def delete_tail(Head):#delete from tail
5151
if Head!=None:
5252
tamp = Node()
5353
tamp = Head
54-
while (tamp.next).next!= None: #find the 2nd last element
54+
while (tamp.next).next!= None:#find the 2nd last element
5555
tamp = tamp.next
56-
tamp.next=None #delete the last element by give next None to 2nd last Element
56+
tamp.next=None#delete the last element by give next None to 2nd last Element
5757
return Head
5858

5959
def isEmpty(Head):
60-
if(Head==None): #check Head is None or Not
61-
return True #return Ture if list is empty
60+
if(Head==None):#check Head is None or Not
61+
return True#return Ture if list is empty
6262
else:
63-
return False #check False if it's not empty
63+
return False#check False if it's not empty
6464

6565

6666

0 commit comments

Comments
 (0)