Insertion in sorted linked list by R4R Team

Example-
Linked list is : 2->4->5->8->9
Insertion of 6
Linked List become : 2->4->5->6->8->9

Function:

void insertion(int n)
{
struct node *ptr=first,*cpt,*newp;
while(ptr->data< n)
{
cpt=ptr;
ptr=ptr->next;
}
newp=(struct node*)malloc(sizeof(struct node));
newp->data=n;
cpt->next=newp;
newp->next=ptr;
}




Leave a Comment: