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

Answer Posted / kushal bagaria

struct node
{
int data;
struct node *list;
};

reverse(&p) /* p is the pointer to the 1st node of ll*/

function reverse:-

reverse(struct node **q)
{
struct node *r,*t,*prev;
r=*q;
prev= NULL;
while(r!=NULL)
{
t=prev;
prev=r;
r=r->link;
prev->link=t;
}
*q=prev; /* last node bcoms d root of ll */
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What's difference between stack and queue?

546


What are the advantage of linked list over array?

458


Tell me can the size of operator be used to tell the size of an array passed to a function?

522


Why do we need searching algorithms?

622


What is the structure of an array?

464






State the difference between arrays and linked lists?

546


Which interfaces are implemented by printerstatereasons?

522


What is structured data with example?

485


Is hashmap faster than arraylist?

465


For addition and deletion. Which one is most preferred: array list or linked list?

516


Can we extend an array after initialization?

582


Can hashmap have same key?

470


What do you mean by separate chaining?

522


Is hashset synchronized?

515


How do you find the index of an element in an arraylist?

441