Skip to content

Recursive solution to insert_tail in singly_LinkedList #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions data_structures/LinkedList/singly_LinkedList.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ def __int__(self,data):
self.data=data#given data
self.next=None#given next to None
class Linked_List:

pass
def insert_tail(Head,data):#insert the data at tail
tamp=Head#create a tamp as a head
if(tamp==None):#if linkedlist is empty
newNod=Node()#create newNode Node type and given data and next
newNod.data=data
newNod.next=None
Head=newNod

def insert_tail(Head,data):
if(Head.next is None):
Head.next = Node(data)
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
insert_tail(Head.next, data)

def insert_head(Head,data):
tamp = Head
if (tamp == None):
Expand All @@ -32,16 +25,18 @@ def insert_head(Head,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()

def printList(Head):#print every node data
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 @@ -50,12 +45,6 @@ def delete_tail(Head):#delete from tail
tamp = tamp.next
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
else:
return False#check False if it's not empty




def isEmpty(Head):
return Head is None #Return if Head is none