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 |
main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }
How will u find whether a linked list has a loop or not?
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }
Is this code legal? int *ptr; ptr = (int *) 0x400;
What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }
char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }
All the combinations of prime numbers whose sum gives 32
why nlogn is the lower limit of any sort algorithm?
Printf can be implemented by using __________ list.
#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }
How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?
Write a program to receive an integer and find its octal equivalent?