We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It worked. but it is bit confusing since there is already a "printSinglyLinkedList(...)" function so I was assuming we need to use this function to print elements.
void ReversePrint(Node *head)
{
// This is a "method-only" submission.
// You only need to complete this method.
if(head){
ReversePrint(head->next);
printf("%d\n",head->data);
}
}
My only conern with this is that a LinkedList could be quite long, and the recursion depth limit is usually only around 5000, which really isn't that deep.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Print in Reverse
You are viewing a single comment's thread. Return to all comments →
Recursion never felt so good :D
That conditional is a bit ugly, why not
nice
here is problem solution in python java c++ and c programming. https://solution.programmingoneonone.com/2020/07/hackerrank-print-in-reverse-solution.html
It worked. but it is bit confusing since there is already a "printSinglyLinkedList(...)" function so I was assuming we need to use this function to print elements.
here is problem solution in python java c++ and c programming. https://solution.programmingoneonone.com/2020/07/hackerrank-print-in-reverse-solution.html
Even shorter:
This will throw a NullPointerException when given head is null. So you might want to handle that.
So true :)
here is problem solution in java python c++ c and javascript programming. https://programs.programmingoneonone.com/2021/05/hackerrank-print-in-reverse-solution.html
So true. :D
void ReversePrint(Node *head) { // This is a "method-only" submission. // You only need to complete this method. if(head){ ReversePrint(head->next); printf("%d\n",head->data); } }
could you please explain your solution? Thanks!!
My only conern with this is that a LinkedList could be quite long, and the recursion depth limit is usually only around 5000, which really isn't that deep.