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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   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
Link list in reverse order.
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Link list in reverse order.
Answer
# 1
recursive reverse(ptr)
  if(ptr->next==NULL)
  return ptr;
  temp=reverse(ptr->next);
  ptr=ptr->next;
  return ptr;
  end
 
Is This Answer Correct ?    1 Yes 1 No
Sameera.adusumilli
 
  Re: Link list in reverse order.
Answer
# 2
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 ?    2 Yes 3 No
Raghuram.A
 
 
 
  Re: Link list in reverse order.
Answer
# 3
/*
the structure is as follows:
struct node
{
   int data;
   struct node *next;
}
*/

struct node * reverse (struct node *home , struct node *rev)
{  
  struct node temp , *p;

  if(home != NULL)
  {
    temp = home;
    while(temp != NULL)
    {
       //this part will create a new node with the name p.
       p = myalloc;
       p -> data = temp -> data;
       p -> next = NULL;
          
       if(rev == NULL)
          rev = p;
       else
       {
              p -> next = rev;
              rev = p;
       }
       temp = temp -> next;
      }
   }
return rev;
}
 
Is This Answer Correct ?    0 Yes 0 No
Shruti
 
  Re: Link list in reverse order.
Answer
# 4
**Liked list as a stack = linked list in reverse order.

/*
the structure is as follows:
struct node
{
   int data;
   struct node *next;
}
*/

struct node * reverse (struct node *home , struct node *rev)
{  
  struct node temp , *p;

  if(home != NULL)
  {
    temp = home;
    while(temp != NULL)
    {
       //this part will create a new node with the name p.
       p = myalloc;
       p -> data = temp -> data;
       p -> next = NULL;
          
       if(rev == NULL)
          rev = p;
       else
       {
              p -> next = rev;
              rev = p;
       }
       temp = temp -> next;
      }
   }
return rev;
}
 
Is This Answer Correct ?    0 Yes 0 No
Shruti
 
  Re: Link list in reverse order.
Answer
# 5
write a link list program to insert integer number and then 
display its sum as well. Your program should display the 
address as well as the result
write a program to reverse a link list so that the last 
element becomes the first one and so on
copy one link list to another list
 
Is This Answer Correct ?    0 Yes 0 No
Aqib
 
  Re: Link list in reverse order.
Answer
# 6
//Go through the code, incase any issues feel free to 
revert.

Copying a link list:

//home is the stationary pointer of the main linked list 
which is to be copied.

//head is the stationary pointer of the new linked list 
which has to be created..

//temp and temp1 are the moving pointers attached to the 
respective linked list...


struct node *copy(struct node *home , struct node *head)
{
  struct node *temp , *temp1 , *p;
  
  temp = home;
  while(temp != NULL)
  {
       p = (struct node *) malloc (sizeof(struct node));
       p -> data = temp -> data;
      
       if(head == NULL)
             head = p;
        
        else
        {
             temp1 = head;
             while(temp1 -> next != NULL)
                   temp1 = temp1 -> next;
               
              temp1 -> next = p;
         }
    temp = temp -> next;
}
return head;
}
 
Is This Answer Correct ?    0 Yes 0 No
Shruti
 
  Re: Link list in reverse order.
Answer
# 7
#include <stdio.h>

typedef struct list
{
 int data;
 struct list * next;
} LIST;

LIST* reverse(LIST *head)
{
  LIST* temp;
  LIST* temp1;

  if (head == NULL || head->next == NULL)
    return head;
  else
  {
    temp = head->next;
    head->next = NULL;
    while(temp)
    {
      temp1 = temp->next;
      temp->next = head;
      head = temp;
      temp = temp1;
    }

    return head;
  }
}

int main(int argc, char ** argv)
{
 int i=0;
 LIST* head = NULL;
 LIST* node = NULL;
 int count;

 if (argc < 2) printf("usage: a.out <count>");
 else count = atoi(argv[1]);

 for (i=0;i<count;i++)
 {
   node = (LIST*)calloc(sizeof(LIST));
   node->data = i;
   node->next = head;

   head = node;
 }

 node = head;
 while(node)
 {
   printf("before %d\n", node->data);
   node = node->next;
 }

 head = reverse(head);
 printf("after head=%d\n", head->data);
 node = head;
 while(node)
 {
   printf("after %d\n", node->data);
   node = node->next;
 }
}
 
Is This Answer Correct ?    2 Yes 1 No
Lijun Li
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { char *p="GOOD"; char a[ ]="GOOD"; printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p)); printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); }  1
#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d..%d",*p,*q); }  1
main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }  1
main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }  1
main() { int i=10; i=!i>14; Printf ("i=%d",i); }  1
main() { char *p = "hello world"; p[0] = 'H'; printf("%s", p); } a. Runtime error. b. “Hello world” c. Compile error d. “hello world” HCL1
void main() { while(1){ if(printf("%d",printf("%d"))) break; else continue; } }  1
main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }  1
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.  2
How we print the table of 2 using for loop in c programing?  1
Derive expression for converting RGB color parameters to HSV values  1
struct point { int x; int y; }; struct point origin,*pp; main() { pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); printf("origin is (%d%d)\n",pp->x,pp->y); }  1
#define max 5 #define int arr1[max] main() { typedef char arr2[max]; arr1 list={0,1,2,3,4}; arr2 name="name"; printf("%d %s",list[0],name); }  1
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];  1
#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }  1
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above HCL1
struct Foo { char *pName; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName); } a. Your Name b. compile error c. Name d. Runtime error HCL1
void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }  1
main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }  1
main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }  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