×

 1 How to print the value contained in linked list in reverse order?? asked 03 Aug '15, 18:25 87●1●4●13 accept rate: 0%

 1 This algorithm would work int func(struct node* temp){ if (temp==NULL) return 0; func(temp->next); printf("%d ",temp->data); return 0; }  or add another pointer that points to the previous element in the list or traverse through the linked list and keep on adding elements to an array print the array in reverse order I hope it helped! answered 03 Aug '15, 19:07 534●2●16 accept rate: 12%
 1 @prrateekk ..no problem at all it works fine.. actually recursive calls also store in stack till you will not get last function call.. but beginner it is quite tough to understand how recursion going on.... that's why i have shown him to demo of stack seprately.... hope you got it... happy coding answered 04 Aug '15, 15:13 1.1k●12●29 accept rate: 6%
 0 if you think that recursive calls is not so visible..how this magic going on than just do one thing just traverse the linked list and push element into stack  while(stack not empty){ printf("%d ",stack.top); stack.pop(); }  or as @prrateekk mention use array and store all value as you iterate and print array element in reverse order..  hope it helps you HAPPY CODING answered 04 Aug '15, 00:58 1.1k●12●29 accept rate: 6% Is there any problem with my recursive code? As I tested it, it works fine. If there's any problem, please let me know (04 Aug '15, 09:50)
 0 Yeah that's right. After all functions execute on stack answered 04 Aug '15, 17:15 534●2●16 accept rate: 12%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

question asked: 03 Aug '15, 18:25

question was seen: 669 times

last updated: 04 Aug '15, 17:15