top of page
Writer's pictureApurba Paul

Singly Linked List- Part 3

The nodes of the List can be deleted from three positions of the List:

1. Delete the last node of the list

2. Delete the first node of the list

3. Delete any preferred node(position is given by user) of the list

_______________________________________________________________________

1. Delete the last node of the list

void del_end() { Node *tptr=start,*temp; while(tptr->Link!=NULL) { temp=tptr; tptr=tptr->Link; } temp->Link=NULL; //printf("%d",temp->info); //tptr->Link=NULL; free(tptr); }

________________________________________________________________________

2. Delete the first node of the list

void del_beg()

{

Node *tptr=start;

start=start->Link;

free(tptr);

}

________________________________________________________________________

3. Delete any preferred node(position is given by user) of the list

void del_anyposition(int pos1) { int step=1; Node *tptr=start,*temp; while(step<pos1) { temp=tptr; tptr=tptr->Link; step++; } temp->Link=tptr->Link; free(tptr); }


13 views0 comments

Recent Posts

See All

Comments


bottom of page