1st Method: by a recursive routine or
2nd Method:using a stack.
1st:Recursive
go to the end then print the nodes, i.e. recursive call comes before printing the node…
void printreverse(node *node1)
{
if (node1)
{
printreverse(node1->link);
printf(“%d -> “,node1->data);
}
}
2nd method: using stack
Push all the nodes, pop one by one and print them
void printreverse(node* node1)
{
node *tmpnode;
Stack *stack = CreateStack();
while(node1)
{
Push(stack, node1);
node1 = node1->next;
}
tmpnode = Pop(stack);
while(tmpnode)
{
tmpnode = Pop(stack);
printf(“%d -> “, tmpnode->data);
}
DestroyStack(stack);
}
November 5, 2011 at 12:00 pm |
promotional items…
[…]printing Reverse of linked list without reversing it actually « TheWarrior[…]…
August 8, 2013 at 11:43 pm |
I like the valuable information you supply in your articles.
I’ll bookmark your blog and check once more here regularly. I am somewhat sure I’ll be told
many new stuff right right here! Good luck for the next!