printing Reverse of linked list without reversing it actually

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);
}

2 Responses to “printing Reverse of linked list without reversing it actually”

  1. promotional items Says:

    promotional items…

    […]printing Reverse of linked list without reversing it actually « TheWarrior[…]…

  2. celebs without makeup Says:

    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!

Leave a reply to promotional items Cancel reply