can i know the source code for reversing a linked list with
out using a temporary variable?

Answers were Sorted based on User's Feedback



can i know the source code for reversing a linked list with out using a temporary variable? ..

Answer / dinakaran gct

#include<stdio.h>
struct node *head;
void main();
{
//consider head is the first node
reverse(head);
//here print the reversed link list ...thank you;
}
reverse(struct node *cur)
{
if(cur->next==NULL)
reveres(cur->next)
else{temp=head=cur;}
temp->next=cur;
temp=temp->next;
temp->next=NULL;
}

Is This Answer Correct ?    2 Yes 1 No

can i know the source code for reversing a linked list with out using a temporary variable? ..

Answer / vishnu948923

struct node* reverse(struct node* first)
{
struct node* cur, temp;
cur=NULL;
while(first!=NULL)
{
temp=first;
first=first->link;
temp->link=cur;
cur=temp;
}
return cur;
}

Is This Answer Correct ?    5 Yes 5 No

can i know the source code for reversing a linked list with out using a temporary variable? ..

Answer / ruchi

void reverse()
{
nptr p;
int i=0;
p=start;
while(p->next!=NULL)
{
p=p->next;
i=i+1;
}
i++;
while(i)
{
printf("%d\n",p->num);
p=p->prev;
i--;
}
}

Is This Answer Correct ?    1 Yes 1 No

can i know the source code for reversing a linked list with out using a temporary variable? ..

Answer / fazil

void Func( struct Node* List )
{
if( List && List->Next )
{
Func( List->Next );

List->Next->Next = List;
}
}

Is This Answer Correct ?    2 Yes 3 No

can i know the source code for reversing a linked list with out using a temporary variable? ..

Answer / zhangwy

void Func( struct Node* List )
{
if( List && List->Next )
{
Func( List->Next );

List->Next->Next = List;
List->next = NULL ;

}
}

Is This Answer Correct ?    0 Yes 1 No

can i know the source code for reversing a linked list with out using a temporary variable? ..

Answer / abdur rab

struct node* reverse ( struct node* head )
{
struct node* temp;

if ( NULL == head -> next ) temp = head;
else {
temp = reverse ( head -> next );
head -> next -> next = head;
head -> next = NULL;
}
return ( temp );
}

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More C Interview Questions

What are c preprocessors?

0 Answers  


what is the difference between getch() and getche()?

7 Answers   Infosys,


HOW TO FIND OUT THE RREVERS OF A GIVEN DIGIT NUMBER IF IT IS INPUT THROUGH THE KEYBORD BY USING C LANGUAGE

3 Answers   Wipro,


Write a program for Overriding.

0 Answers  


What is true about the following C Functions a.Need not return any value b.Should always return an integer c.Should always return a float d.Should always return more than one value.

11 Answers   TCS,






What is a spanning Tree?

1 Answers   TCS,


What are unions in c?

0 Answers  


how can i get the string which is having two spaces at the end.suppose the string is "Hello World ".Now at the end i have two spaces.i need to print with that spaces .

1 Answers  


What's the best way of making my program efficient?

0 Answers   Celstream,


wt is d full form of c

6 Answers   TCS, Wipro,


Why is void main used?

0 Answers  


7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.

0 Answers  


Categories