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..

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..

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..

we can insert using binary search.

 Is This Answer Correct ? 3 Yes 10 No

write a program to Insert in a sorted list..

node *SLSortWiseInsert(node *START, int data)
{

node *newnode;
if(START == NULL)
{
START = (node *)malloc(sizeof(node));
START->data = data;
return START;
}
else if(data < START->data)
{
newnode = (node *)malloc(sizeof(node));
newnode->data = data;
return newnode;
}
else if((data > START->data) && (START->link == NULL))
{
printf("Inside this condition\n");
newnode = (node *)malloc(sizeof(node));
newnode->data = data;
return START;
}
return START;
}

 Is This Answer Correct ? 1 Yes 8 No

More C Code Interview Questions

#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }

Derive expression for converting RGB color parameters to HSV values

¦void main() ¦{ ¦int i=10,j; ¦ j=i+++i+++i; ¦printf("%d",j); ¦getch(); ¦} ¦ output:-30 but in same question if we write as- ¦void main() ¦{ ¦int i=10; ¦ int j=i+++i+++i; ¦printf("%d",j); ¦getch(); ¦} ¦ output:-33 why output is changed from 30 to 33. Can any body answer...

how can i cast a char type array to an int type array

#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }

main() { void swap(); int x=10,y=8; swap(&x,&y); printf("x=%d y=%d",x,y); } void swap(int *a, int *b) { *a ^= *b, *b ^= *a, *a ^= *b; }

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.

main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }

Sorting entire link list using selection sort and insertion sort and calculating their time complexity