Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

program to Reverse a linked list

Answers were Sorted based on User's Feedback

program to Reverse a linked list..

node *reverse(node *first)

{
node *cur,*temp;

cur=NULL;

while(first!=NULL)

{temp=first;

cur=temp;
}

return cur;

}

 Is This Answer Correct ? 136 Yes 52 No

program to Reverse a linked list..

reverse a linked list -> by creating a new list.

consider home as the stationary pointer of the original list

the node structure is as follows:

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

struct node * reverse(struct node *home , struct node *
start)
temp = home;
while(temp != NULL)
{
p = (struct node *) malloc (sizeof(struct node));
p -> data = temp -> data;
p -> next = NULL;

if(start == NULL)
start = p;

else
{
p -> next = start;
start = p;
}

temp = temp -> next;

return start;
}

 Is This Answer Correct ? 42 Yes 16 No

program to Reverse a linked list..

void reverse(struct node **kbr)
{
struct node *temp,*p,*q;
temp=*kbr;
p=temp->next;
q=temp;
while(p!=NULL)
{
temp=p;
p=p->next;
temp->next=q;
q=temp;
}
(*kbr)->next=NULL;
*kbr=q;
}

 Is This Answer Correct ? 24 Yes 16 No

program to Reverse a linked list..

void reverse(list *l)
{
lnode *temp;
temp=l->first;
while(temp->next != NULL)
{
temp=temp->next;
}
while(temp !=NULL)
{
printf("%d",temp->info);
temp=temp->prev;
}
}

 Is This Answer Correct ? 15 Yes 12 No

program to Reverse a linked list..

void rev(node *nPtr, node *prevPtr)
{
if(nPtr->next==NULL)
{
}
else
{
rev(nPtr->next, nPtr);
}
nPtr->next=prevPtr;
prevPtr->next=NULL;
}

 Is This Answer Correct ? 3 Yes 1 No

program to Reverse a linked list..

/* Reverse linked list by recursion */

NodeStr *preNode,
NodeStr *node1,
NodeStr *node2
)
{
NodeStr *next_node;

if(!node2)
return node1;

next_node = node2->next;
node2->next = node1;
node1->next = preNode;
}

 Is This Answer Correct ? 11 Yes 11 No

program to Reverse a linked list..

{
p->next=NULL;
temp=p;
while(p!=tail)
{
q->next=p;
p=q;
if(r!=NULL)
{
q=r;
r=q->next;
}
}
tail=temp;
}

 Is This Answer Correct ? 0 Yes 0 No

program to Reverse a linked list..

void reverse(Node_t *nPtr, Node_t *prevPtr){

if(nPtr->next != NULL){
reverse(nPtr->next, nPtr);
}
else{
}
nPtr->next = prevPtr;
}

 Is This Answer Correct ? 7 Yes 8 No

program to Reverse a linked list..

Program to reverse a singly list ITERATIVELY,

Program to reverse a linked list RECURSIVELY

 Is This Answer Correct ? 4 Yes 7 No

program to Reverse a linked list..

int rec_rev(node *p) {
node *last_prev,*last,*temp,*q;
if (p->next==NULL)
return 1;
else {
last_prev=find_last(); // finds last but 1 element
last=last_prev->next;
last_prev->next==NULL;
p=temp;
rec_rev(p);
}
else {
q=find_prev(p);
last->next=q->next;
q->next=last;
q->next->next=p;
rec_rev(p);
}
}
]

 Is This Answer Correct ? 3 Yes 7 No

More C Code Interview Questions

What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100); assert(s != NULL); return s; }

What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

main() { int i; i = abc(); printf("%d",i); } abc() { _AX = 1000; }

respected sir, i did my MCA in 2013 when i am going to attend to an interview i was asked about my project how will i explain my project could please help me in this and my project title is "Social Networking Site For Social Responsibility"

main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }

Write a single line c expression to delete a,b,c from aabbcc

what is the output of the below program & why ? #include<stdio.h> void main() { int a=10,b=20,c=30; printf("%d",scanf("%d%d%d",&a,&b,&c)); }

union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0

prog. to produce 1 2 3 4 5 6 7 8 9 10

what is variable length argument list?

How can i find first 5 natural Numbers without using any loop in c language????????

given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit

Categories