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 does %p mean?

0 Answers  


can u write a program in C, which does not use = (eqaul)or any arithmatic assignment(like -=,+=,*= etc) operator to swap to number?

2 Answers  


Explain the difference between fopen() and freopen().

2 Answers  


What is C language Terminator?

15 Answers   TCS,


What tq means in chat?

0 Answers  


main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none

0 Answers  


c program to print a name without using semicolon

9 Answers   TCS, Wipro,


Why is c called a mid-level programming language?

0 Answers  


program to find out date after adding 31 days to a date in the month of febraury also consider the leap year

0 Answers  


what is the difference between #include<> and #include”…”?

5 Answers  


CAN WE DEFINE ANY FUNCTION WITHIN A FUNCTION.

15 Answers  


Why do we use int main instead of void main in c?

0 Answers  


Categories