Skip to content
Merged
Prev Previous commit
Next Next commit
Update singly_LinkedList.py
  • Loading branch information
avkaran-singh authored Sep 8, 2017
commit 3ee70b3d5b66293cd550f0f538bef97843664d24
14 changes: 2 additions & 12 deletions data_structures/LinkedList/singly_LinkedList.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,41 @@ def insert_tail(Head,data): #insert the data at tail
newNod.data=data
newNod.next=None
Head=newNod

else:
while tamp.next!=None: #find the last Node
tamp=tamp.next
newNod = Node() #create a new node
newNod.data = data
newNod.next = None
tamp.next=newNod #put the newnode into last node

return Head #return first node of linked list

def insert_head(Head,data):
tamp = Head
if (tamp == None):
newNod = Node() #create a new Node
newNod.data = data
newNod.next = None
Head = newNod #make new node to Head

Head = newNod #make new node to Head
else:
newNod = Node()
newNod.data = data
newNod.next = Head #put the Head at NewNode Next
Head=newNod # make a NewNode to Head
return Head



def Print(Head): #print every node data
tamp=Node()
tamp=Head
while tamp!=None:
print(tamp.data)
tamp=tamp.next



def delete_head(Head): #delete from head
if Head!=None:
Head=Head.next

return Head #return new Head



def delete_tail(Head): #delete from tail
if Head!=None:
tamp = Node()
Expand All @@ -65,7 +56,6 @@ def delete_tail(Head): #delete from tail
tamp.next=None #delete the last element by give next None to 2nd last Element
return Head


def isEmpty(Head):
if(Head==None): #check Head is None or Not
return True #return Ture if list is empty
Expand Down