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

how can u draw a rectangle in C

53 Answers   Accenture, CO, Codeblocks, Cognizant, HCL, Oracle, Punjab National Bank, SAP Labs, TCS, University, Wipro,


How can you relate the function with the structure? Explain with an appropriate example.

0 Answers  


#define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }

4 Answers   Google, HCL, Quick Heal, WTF,


const int perplexed = 2; #define perplexed 3 main() { #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed); } a. 0 b. 2 c. 4 d. none of the above

1 Answers   emc2, HCL,


what is the code of the output of print the 10 fibonacci number series

2 Answers  






Find the largest number in a binary tree

7 Answers   Infosys,


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 Answers  


main() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; printf("\n%d %d %d",a,*f1,*f2); }

6 Answers  


main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

3 Answers   GNITC,


write a c program to Create a mail account by taking the username, password, confirm password, secret_question, secret_answer and phone number. Allow users to register, login and reset password(based on secret question). Display the user accounts and their details .

2 Answers  


write a c program to Reverse a given string using string function and also without string function

1 Answers  


What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100); assert(s != NULL); return s; }

1 Answers  


Categories