Skip to content

Instantly share code, notes, and snippets.

@Svastikkka
Created August 5, 2020 09:06
Show Gist options
  • Save Svastikkka/da012a1b851ed67005d5d068bd111847 to your computer and use it in GitHub Desktop.
Save Svastikkka/da012a1b851ed67005d5d068bd111847 to your computer and use it in GitHub Desktop.
class Node:
def __init__(self, data):
self.data = data
self.next = None
def LinkedLists(arr):
head = None
tail = None
if len(arr) < 1:
return -1
else:
for i in arr:
if i == -1:
break
NewNode = Node(i)
if head == None:
head = NewNode
tail = NewNode
else:
tail.next = NewNode
tail = NewNode
return head
def printReverse(head) :
prev = None
current = head
while (current is not None):
next = current.next
current.next = prev
prev = current
current = next
head = prev
printLL(head)
def printLL(head):
while head is not None:
print(head.data, end=" ")
head = head.next
t = int(input())
for i in range(t):
arr = list(map(int, input().split()))
printReverse(LinkedLists(arr))
@Svastikkka
Copy link
Author

Print Reverse LinkedList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment