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   To Refer this Site to Your Friends   Click Here
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 ?    16 Yes 2 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 ?    6 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 ?    4 Yes 5 No
Shruthirap
 
  Re: program to Reverse a linked list
Answer
# 4
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 ?    0 Yes 0 No
Gaurav Jain
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above HCL1
main() { 41printf("%p",main); }8  1
What is "far" and "near" pointers in "c"...?  3
main() { extern out; printf("%d", out); } int out=100;  1
Program to Delete an element from a doubly linked list. Infosys4
void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }  1
main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }  1
const int perplexed = 2; #define perplexed 3 main() { #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed); } a. 0 b. 2 c. 4 d. none of the above HCL1
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.  5
#include"math.h" void main() { printf("Hi everybody"); } if <stdio.h> will be included then this program will must compile, but as we know that when we include a header file in "" then any system defined function find its defination from all the directrives. So is this code of segment will compile? If no then why?  2
What is the main difference between STRUCTURE and UNION?  5
#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above HCL1
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h  1
main() { extern int i; i=20; printf("%d",i); }  1
Print an integer using only putchar. Try doing it without using extra storage.  1
main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }  1
int swap(int *a,int *b) { *a=*a+*b;*b=*a-*b;*a=*a-*b; } main() { int x=10,y=20; swap(&x,&y); printf("x= %d y = %d\n",x,y); }  1
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
main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }  1
main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf("%d\n",++k); printf("%f\n",f<<2); printf("%lf\n",f%g); printf("%lf\n",fmod(f,g)); }  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