write a program to Insert in a sorted list

Answers were Sorted based on User's Feedback



write a program to Insert in a sorted list..

Answer / raghuram.a

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 ?    10 Yes 5 No

write a program to Insert in a sorted list..

Answer / prof.muthu(9962940220)

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 ?    3 Yes 5 No

write a program to Insert in a sorted list..

Answer / shruti

we can insert using binary search.

Is This Answer Correct ?    3 Yes 10 No

write a program to Insert in a sorted list..

Answer / kathiresan

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 ?    1 Yes 8 No

Post New Answer

More C Code Interview Questions

main() { int i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) { printf(“%s\n”,x); x++; } }

2 Answers  


main() { int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j); }

1 Answers  


main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }

1 Answers  


How will you print % character? a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”)

4 Answers   HCL,


void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above

1 Answers   HCL,






Write a program to receive an integer and find it's octal equivalent. How can i do with using while loop.

2 Answers  


abcdedcba abc cba ab ba a a

2 Answers  


posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0;i<=3;i++) printf("%02x",(unsigned char) p[i]); } how is the output of this program is :: 0000ac40 please let me know y this output has come

2 Answers   GATE,


What is the hidden bug with the following statement? assert(val++ != 0);

1 Answers  


Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


void main() { int i=5; printf("%d",i++ + ++i); }

3 Answers  


main() { int i=10; i=!i>14; Printf ("i=%d",i); }

1 Answers  


Categories