create an singly linked lists and reverse the lists by
interchanging the links and not the data?

Answer Posted / sumit garg( jmit mca)

\\HELLO FRIENDS CHEK THIS...IT IS TESTED\\
struct node
{
int info;
struct node * next;
};
struct node * ptr=NULL,* old=NULL,*save=NULL;
void reverse()
{
old=ptr=start;
while (ptr!=NULL)
{
ptr=ptr->next;
old->next=save;
push(old);
save=old;
old=ptr;
}
}
void push(struct node * p)
{
top++;
stack [top]=p;
}
struct node * pop()
{
struct node * ret=NULL;
ret=stack[top];
top=top-1;
return ret;
}
display(struct node * disp)
{
disp=stack[top];
while (disp->next!=NULL)
{
disp=pop();
printf("%d",disp->info);
}

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me the difference between structure and array?

470


Define dynamic data structures?

554


In rdbms, explain what is the efficient data structure used in the internal storage representation?

531


Which is faster hashmap or treemap?

489


Can we put null key in hashmap?

490






What does list clear do?

482


Which sorting algorithm is best for large data?

471


What are skew trees? For a tree with 4 nodes draw all possible binary? Generalize for n nodes how many binary trees can be drawn?

631


Explain the Stack

557


What is linear and non linear structure?

495


How many links are there in a binary tree of N nodes?

601


Run time memory allocation is known as ?

564


Does treemap allow null values?

472


Why is data structure important?

533


What is a minimum spanning tree?

557