Skip to content
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
20 changes: 19 additions & 1 deletion Data Structures and Algorithms/linked_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def insert(self, data, index):
current = self.head

while position > 1:
current = node.next_node
current = current.next_node
position -= 1

prev_node = current
Expand Down Expand Up @@ -139,3 +139,21 @@ def __repr__(self):

current = current.next_node
return "->".join(nodes)

def reverse(self):
"""
reverses the complete linked list
returns the linked list
the time complexity of it is 0(n) time.
"""
first = self.head
second = self.head.next_node

while(second != None):
store_rest_list = second.next_node
second.next_node = first
first = second
second = store_rest_list
self.head.next_node = None
self.head = first
return self