Deletion in linked list

 Deletion in linked list

CASES IN DELETION

CASE 1: DELETING THE FIRST NODE

CASE 2: DETEING A NODE BETWEEN

CASE 3: DELETING THE LAST NODE

CASE 4: DELETING A NODE WITH A GIVEN

VALUE/DATA

CASE 1: DELETING THE FIRST NODE

HEAD

HEAD head NULL


Struct Node *ptr=head

Head=head->next;

Free(ptr);

Case 2: CASE 2: DETEING A NODE BETWEEN

Index 2;

Struct Node *p=head;

While(){

p->p->next;

}

4 3 8 1


Struct Node *q ,p->next;

p->next=q->next;

free(q);

CASE 3: DELETING THE LAST NODE

p->next=NULL;

FREE(q);

CODE FOR CASES:

Printf(“linked list before deletion\n”);

linkedlistTraversal(head);

head=deletefirst(head);

printf(“linkedlist after deletion/n”);

linkedlistTravelsal(head);

case 1: deleting the first element from linked

list

struct Node*deletefirst(struct Node* head)

{

Struct Node * ptr=head;


Head=head->next;

Free(ptr)

Return head;

}

Int main()

……..


CASE 2:

Struct node deleteatindex=(struct Node*head, int index)

{

Struct Node * p=head;

Struct Node*q=head->next;

For(int i=o,i<index-1,i++)

{

P=p->next;

Q=q->next

}


pnext=q->next

free(q)

}

CASE 3 : DELETE THE LAST NODE

Struct node *deleteatend(struct node head, int head)

Struct node *p=head;

Struct node *q=head->next;

While(q->next1=null)

{

P=p-next;

Q=q-next;

}

p->next=null;

free(q);

return head;

}

Int main()

Comments

Popular posts from this blog

Bihar Board 12th Result 2022 - Check BSEB Inter Result at BiharBoardonline.Bihar.gov.in

Chennai Super Kings against Mumbai Indians in Mumbai

BSEB 12th Result 2022 – biharboardonline.bihar.gov.in, Download Link