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

write a program to print data of 5 five students with structures?

0 Answers  


write a program in c to read array check element is present or not?

1 Answers  


What is pass by reference in functions?

0 Answers  


Why cd or dvd are round why not square.

1 Answers  


write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?

0 Answers   Wipro,


To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

0 Answers   HCL,


yogesh patil in dell

3 Answers   DELL,


what is a function method?give example?

0 Answers  


In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)

0 Answers   Wipro,


How does variable declaration affect memory?

1 Answers  


Is stack a keyword in c?

0 Answers  


write a function that accepts an integer/char array and an search item.If the search item is there in the array return position of array and value else return -1.without using other array,without sorting,not to use more than one loop?

3 Answers   Mind Tree,


Categories