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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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
write a program to Insert in a sorted list
 Question Submitted By :: =-PKG-=
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write a program to Insert in a sorted list
Answer
# 1
node *insert(node *first,int data)
{node *temp,*trav,*cur;
temp->info=data;
temp->next=NULL;
trav=first;
if(data<trav->info)
{temp->next=first;
first=temp;
return first;
}
while(data>trav->info&&trav->next!=NULL)
{cur=trav;
trav=trav->next;
}
if(data>trav->info&&trav->next==NULL)
trav->next=temp;
else
{cur->next=temp;
temp->next=trav;
}
return first;
}
 
Is This Answer Correct ?    4 Yes 1 No
Raghuram.A
 
  Re: write a program to Insert in a sorted list
Answer
# 2
we can insert using binary search.
 
Is This Answer Correct ?    1 Yes 3 No
Shruti
 
 
 
  Re: write a program to Insert in a sorted list
Answer
# 3
PLEASE INSERT IN SORTED ORDER....SO,THERE IS NO DIFICULTY OF
 RE-ARRANGING THE ELEMENTS...
  GOT IT...?
                           BY THE GREAT PROF.MUTHU
                           PH:9962940220
 
Is This Answer Correct ?    1 Yes 1 No
Prof.muthu(9962940220)
 
  Re: write a program to Insert in a sorted list
Answer
# 4
node *SLSortWiseInsert(node *START, int data)
{

        node *newnode;
        if(START == NULL)
        {
                START = (node *)malloc(sizeof(node));
                START->data = data;
                START->link = NULL;
                return START;
        }
        else if(data < START->data)
        {
                 newnode = (node *)malloc(sizeof(node));
                 newnode->data = data;
                 newnode->link = START;
                 return newnode;
        }
        else if((data > START->data) && (START->link == NULL))
        {
                printf("Inside this condition\n");
                newnode = (node *)malloc(sizeof(node));
                newnode->data = data;
                newnode->link = NULL;
                START->link = newnode;
                return START;
        }
        START->link = SLSortWiseInsert(START->link,data);
        return START;
}
 
Is This Answer Correct ?    0 Yes 4 No
Kathiresan
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }  1
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }  1
void main() { char ch; for(ch=0;ch<=127;ch++) printf(“%c %d \n“, ch, ch); }  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() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); } } a. 512, 256, 0, 0, 0 b. 256, 256, 0, 0, 0 c. 512, 512, 512, 512, 512 d. 256, 256, 256, 256, 256 HCL1
main() { clrscr(); } clrscr();  1
How will u find whether a linked list has a loop or not? Microsoft6
main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }  1
Printf can be implemented by using __________ list.  1
main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(“%d” ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(“%d ” ,*p); p++; } }  1
#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }  1
main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }  1
main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O HCL2
Give a oneline C expression to test whether a number is a power of 2? Motorola16
main() { int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i); } a. 20, 10, 20, 10 b. 20, 9, 20, 10 c. 20, 9, 19, 10 d. 19, 9, 20, 10 HCL1
main() { char *cptr,c; void *vptr,v; c=10; v=0; cptr=&c; vptr=&v; printf("%c%v",c,v); }  1
void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }  1
main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); }  1
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }  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
 
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