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                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
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 ?    18 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 ?    1 Yes 0 No
Gaurav Jain
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
What is "far" and "near" pointers in "c"...?  3
main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); }  1
How to swap two variables, without using third variable ? HCL46
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it. Microsoft7
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }  1
There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong? void main() { struct student { char name[30], rollno[6]; }stud; FILE *fp = fopen(“somefile.dat”,”r”); while(!feof(fp)) { fread(&stud, sizeof(stud), 1 , fp); puts(stud.name); } }  1
main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }  1
#include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"); return 0; } void fun(int i) { if(n>0) { fun(--n); printf("%d",n); fun(--n); } } the answer is 0 1 2 0..someone explain how the code is executed..? Wipro1
#if something == 0 int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }  1
main() { int x=5; clrscr(); for(;x==0;x--) { printf("x=%d\n”", x--); } } a. 4, 3, 2, 1, 0 b. 1, 2, 3, 4, 5 c. 0, 1, 2, 3, 4 d. none of the above HCL1
Printf can be implemented by using __________ list.  1
Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like. Microsoft15
void main() { static int i=5; if(--i){ main(); printf("%d ",i); } }  1
main() { show(); } void show() { printf("I'm the greatest"); }  1
main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; } a. Runtime error. b. Runtime error. Access violation. c. Compile error. Illegal syntax d. None of the above HCL1
main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }  1
main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }  1
How do you write a program which produces its own source code as its output?  7
What is the subtle error in the following code segment? void fun(int n, int arr[]) { int *p=0; int i=0; while(i++<n) p = &arr[i]; *p = 0; }  1
how to return a multiple value from a function? Wipro5
 
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