Given a linked list of integers sorted in an ascending order and a pointer to a single node containing an integer write a C program that insert the node P in the linked list so that remains sorted?

1 answer

Answer

1165359

2026-08-20 04:36

+ Follow

InsertNode(NODE **q,int num)

{

NODE *r,*temp ;

temp = *q;

r= malloc(sizeof(NODE));

r->data = num;

//if it's fisrt node to be inserted

if ( *q == NULL num < (*q)->data)

{

*q = r ;

(*q)->link=temp;

}

else

{

while(temp)

{

if ( (num > temp->data) && (num < temp->link->data ) )

{

r->link = temp->link;

temp->link = r;

return;

}

temp = temp->link;

}

r->link = NULL;

temp->link = r;

}

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.