mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 13:31:07 +00:00
Update singly_LinkedList.py
This commit is contained in:
parent
d043448fd9
commit
a88ad60365
|
@ -9,7 +9,7 @@ class Node: # create a Node
|
||||||
|
|
||||||
class Linked_List:
|
class Linked_List:
|
||||||
def insert_tail(Head, data):
|
def insert_tail(Head, data):
|
||||||
if(Head.next is None):
|
if Head.next is None:
|
||||||
Head.next = Node(data)
|
Head.next = Node(data)
|
||||||
else:
|
else:
|
||||||
Head.next.insert_tail(data)
|
Head.next.insert_tail(data)
|
||||||
|
@ -43,7 +43,7 @@ class Linked_List:
|
||||||
if Head is not None:
|
if Head is not None:
|
||||||
tamp = Node()
|
tamp = Node()
|
||||||
tamp = Head
|
tamp = Head
|
||||||
while (tamp.next).next is not None: # find the 2nd last element
|
while tamp.next.next is not None: # find the 2nd last element
|
||||||
tamp = tamp.next
|
tamp = tamp.next
|
||||||
# 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
|
tamp.next = None
|
||||||
|
@ -56,7 +56,7 @@ class Linked_List:
|
||||||
prev = None
|
prev = None
|
||||||
current = Head
|
current = Head
|
||||||
|
|
||||||
while(current):
|
while current:
|
||||||
# Store the current node's next node.
|
# Store the current node's next node.
|
||||||
next_node = current.next
|
next_node = current.next
|
||||||
# Make the current node's next point backwards
|
# Make the current node's next point backwards
|
||||||
|
|
Loading…
Reference in New Issue
Block a user