Created
May 9, 2016 20:24
-
-
Save jianminchen/91e8dfeac0e962307b30f4afd0bb6f98 to your computer and use it in GitHub Desktop.
HackerRank - Linked List - reverse print
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Print elements of a linked list in reverse order as standard output | |
head pointer could be NULL as well for empty list | |
Node is defined as | |
struct Node | |
{ | |
int data; | |
struct Node *next; | |
} | |
*/ | |
void ReversePrint(Node *head) | |
{ | |
if(head==NULL) | |
return; | |
if(head->next==NULL) | |
{ | |
printf("%d\n", head->data); | |
return; | |
} | |
ReversePrint(head->next); | |
printf("%d\n", head->data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment