ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
program to Reverse a linked list
 Question Submitted By :: =-PKG-=
I also faced this Question!!     Rank Answer Posted By  
 
  Re: program to Reverse a linked list
Answer
# 1
node *reverse(node *first)


{
node *cur,*temp;


cur=NULL;

while(first!=NULL)


{temp=first;

first=first->link;

temp->link=cur;

cur=temp;
}

return cur;

}
 
Is This Answer Correct ?    4 Yes 0 No
Raghuram
 
  Re: program to Reverse a linked list
Answer
# 2
reverse a linked list -> by creating a new list.

consider home as the stationary pointer of the original list
adn start as the stationary pointer of the new linked 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 ?    2 Yes 0 No
Shruti
 
 
 
  Re: program to Reverse a linked list
Answer
# 3
node *reverse(node *first)
{
   node *temp = NULL;

   if(first->next != NULL)
   {
        temp = reverse(first->next);
        temp->next = first;
        return first;
   }
   else
        return first;
}
//The only catch is that the supposed to be first node after
reordering, has to be kept either in some global pointer or
passed back by function. That's it :)
 
Is This Answer Correct ?    1 Yes 0 No
Shruthirap
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
Write a function to find the depth of a binary tree. Adobe4
how to return a multiple value from a function? Wipro4
how to check whether a linked list is circular.  3
plz send me all data structure related programs  1
How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com Deshaw8
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h  1
Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution) Microsoft4
Write a C function to search a number in the given list of numbers. donot use printf and scanf Honeywell4
Give a one-line C expression to test whether a number is a power of 2. Microsoft7
Finding a number multiplication of 8 with out using arithmetic operator NetApp7
Program to find the largest sum of contiguous integers in the array. O(n)  5
How to return multiple values from a function?  4
write the function. if all the character in string B appear in string A, return true, otherwise return false. Google7
How to swap two variables, without using third variable ? HCL28
print numbers till we want without using loops or condition statements like specifically(for,do while, while swiches, if etc)!  7
why java is platform independent? Wipro6
Write a program that find and print how many odd numbers in a binary tree  1
How will u find whether a linked list has a loop or not? Microsoft3
How do you sort a Linked List (singly connected) in O(n) please mail to pawan.10k@gmail.com if u can find an anser...i m desperate to knw... Oracle3
program to find the roots of a quadratic equation  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com