Skip to content

Fix unresolved name: insert_tail() #243

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 2 commits into from
Jan 22, 2018
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
78 changes: 40 additions & 38 deletions data_structures/LinkedList/singly_LinkedList.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,69 @@
from __future__ import print_function
class Node:#create a Node
def __int__(self,data):
self.data=data#given data
self.next=None#given next to None


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

def insert_head(Head,data):
def insert_head(Head, data):
tamp = Head
if (tamp == None):
newNod = Node()#create a new Node
if tamp is 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 printList(Head):#print every node data
tamp=Head
while tamp!=None:
newNod.next = Head # put the Head at NewNode Next
Head = newNod # make a NewNode to Head
return Head

def printList(Head): # print every node data
tamp = Head
while tamp is not 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 = tamp.next

def delete_head(Head): # delete from head
if Head is not None:
Head = Head.next
return Head # return new Head

def delete_tail(Head): # delete from tail
if Head is not None:
tamp = Node()
tamp = Head
while (tamp.next).next!= None:#find the 2nd last element
while tamp.next.next is not None: # find the 2nd last element
tamp = tamp.next
tamp.next=None#delete the last element by give next None to 2nd last Element
# delete the last element by give next None to 2nd last Element
tamp.next = None
return Head

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

def reverse(Head):
prev = None
current = Head
while(current):
# Store the current node's next node.

while current:
# Store the current node's next node.
next_node = current.next
# Make the current node's next point backwards
current.next = prev
# Make the previous node be the current node
prev = current
# Make the current node the next node (to progress iteration)
current = next_node
# Return prev in order to put the head at the end
# Return prev in order to put the head at the end
Head = prev