Print a linkedlist in Reverse order [HackerRank] | Data Structure | LinkedList

preview_player
Показать описание
This video is about Print a linkedlist in Reverse order.

Problem Statement:
You are given the pointer to the head node of a linked list and you need to print all its elements in reverse order from tail to head, one element per line. The head pointer may be null meaning that the list is empty - in that case, do not print anything!

#HackerRank #DataStructure #LinkedList
Problem:

Code Sample:
#without recursion
def reversePrint(head):
p1=head
lst=list()
while p1 is not None:
while len(lst):

#with recursion
def reversePrint(head):
if head is None:
return

Linear Linked List in detail

For 1 : 1 Tutoring
WhatsApp contact : 7278222619

Follow me on:
Whatsapp:

Facebook:

Linkedin:

Instagram:
Рекомендации по теме
Комментарии
Автор

Hey Programmer, if you have any alternative solution feel free to post in comment section.

codingcart
Автор

the answer with the recursion what does it mean return after the if statement of head is None?
what i had understand before that in any definition of a function the return mean what we get in the end from this function either it is a value or printing something or an object

shaimaamar
Автор

def reversePrint(head):
previous = None
nextnode = None
current = head
while current:
nextnode = current.next
current.next = previous
previous = current
current = nextnode
return print_singly_linked_list(previous, "\n")

this is not printing the output format properly what should i do please check it i dont want to use recursion

rushilkumar
join shbcf.ru