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

Write code for reversing a linked list.

614


What are common data structures?

680


Define right-in threaded tree?

635


Sorting is not possible by using which of the methods?

561


What is collection sort?

574






State the difference between primitive and non-primitive data types?

754


Explain singly linked list in short.

618


Is array size dynamic or fixed?

596


Tell me what should be done in the base case for this recursive problem?

566


what is Singly Linked list?

668


Can we extend an array after initialization?

663


Why linked lists are better than arrays?

595


What is collision in data structure?

572


What should I learn first data structures or algorithms?

672


Which algorithm is used in collections sort method?

544