## Saturday, May 26, 2007

Use Recursion.

Anonymous said...

This is no possible in case of singale linked list because we don't have back address

Belamge, Pundaleek said...

One way to do this is using recursive operation

Other way is through LIFO data structure

Anonymous said...

Ya I agree, we can use Stack, and push the elements in stack. and after the POP it till the stack is empty.

Anonymous said...

Can we not write recursive program like

void PrintListFromBack(LIST * Root)
{
if(!Root)
return;
else
if(Root->next)
PrintListFromBack(Root->Next);

printf("%d", Root->info);
}

Anonymous said...

1] Stack solution
2] Recursive function
3] Reverse list and print

Anonymous said...

build another list.

Lakhvir Singh said...

int print_reverse(list *ptr){
if(ptr==NULL)
return 0;
else{
printf(" %d ",ptr->data);
}
return 0;
}

Anonymous said...

first reverse the list and read

Anonymous said...

algorithm to reverse a singly linked list:

top=null
{
temp = start
start = start.next
temp.next = top
top = temp
}

correct, no?

Anonymous said...

CORRECT SOLUTION IS

void PrintListFromBack(LIST * Root)
{
if(!Root)
return;
else
if(Root->next)
PrintListFromBack(Root->Next);

printf("%d", Root->info);
}

Anonymous said...

Copied from cracktheinterview. word to word

Anonymous said...

The solution given with the function PrintListFromBack is a good one and make sense.

Priyanka kumari said...

one way void readfrmbck(struct node *start)
{
if(start==NULL)
return;

//printf("%d",start->data);
printf("%d",start->data);
}to solve this question is:

bunny said...

one way to solve this is: