write a program to Insert in a sorted list
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
why nlogn is the lower limit of any sort algorithm?
void main() { int const * p=5; printf("%d",++(*p)); }
3 Answers Infosys, Made Easy, State Bank Of India SBI,
Give a one-line C expression to test whether a number is a power of 2.
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h
Who could write how to find a prime number in dynamic array?
In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }
main() { extern out; printf("%d", out); } int out=100;
Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }
PROG. TO PRODUCE 1 1 1 1 2 1 1 3 3 1 1 4 6 4 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]); }
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }