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 is list and types of list?

551


What is the difference between a push and a pop?

624


What is a data structure? What are the types of data structures?

630


Can you store different types in an array?

578


Have you ever used HashTable and Directory?

661






Which sorting is best and why?

573


How do you make a bubble chart with 3 variables?

558


What is the difference between array and stack?

613


Explain the most efficient method to reverse a linked list?

566


Explain the terms base case, recursive case, binding time, run-time stack and tail recursion.

536


How do I sort a hashmap key?

572


What is the best time complexity of bubble sort?

602


What is the most used data structure?

541


How to excel in data structures and algorithms?

612


What is array and string?

560