Skip to content

Commit d784139

Browse files
Update singly_LinkedList.py
1 parent fcd5ac1 commit d784139

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

data_structures/LinkedList/singly_LinkedList.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ def __int__(self,data):
33
self.data=data #given data
44
self.next=None #given next to None
55

6-
7-
8-
96
class Linked_List:
107
pass
118
def insert_tail(Head,data): #insert the data at tail
@@ -32,14 +29,13 @@ def insert_head(Head,data):
3229
newNod.data = data
3330
newNod.next = None
3431
Head = newNod #make new node to Head
35-
return Head
32+
3633
else:
3734
newNod = Node()
3835
newNod.data = data
3936
newNod.next = Head #put the Head at NewNode Next
4037
Head=newNod # make a NewNode to Head
41-
42-
return Head
38+
return Head
4339

4440

4541

@@ -53,35 +49,28 @@ def Print(Head): #print every node data
5349

5450

5551
def delete_head(Head): #delete from head
56-
if Head==None:
57-
print("List is empty cannot delete")
58-
59-
else:
52+
if Head!=None:
6053
Head=Head.next
6154

6255
return Head #return new Head
6356

6457

6558

6659
def delete_tail(Head): #delete from tail
67-
if Head==None:
68-
print("List is empty cannot delete")
69-
else:
60+
if Head!=None:
7061
tamp = Node()
7162
tamp = Head
7263
while (tamp.next).next!= None: #find the 2nd last element
7364
tamp = tamp.next
74-
tamp.next=None #delete the last element by give next None to 2nd last Element
75-
65+
tamp.next=None #delete the last element by give next None to 2nd last Element
66+
return Head
7667

7768

7869
def isEmpty(Head):
7970
if(Head==None): #check Head is None or Not
80-
print("list is empty")
81-
return True #return Ture if it is none
71+
return True #return Ture if list is empty
8272
else:
83-
print("Not empty")
84-
return False #check False if it's not none
73+
return False #check False if it's not empty
8574

8675

8776

0 commit comments

Comments
 (0)