This part of Linear Single Linked List will tell you how to delete a node at any index. It’s simple like adding a data, you just have to change the node pointer to other that next to the node that you want to delete. If you want to delete the most front data, you have to set the head onto the next node and delete the first node. Looks like front, when we want to delete the last node, we have to set the 2nd node from the last to tail and delete the last data/ node.

Delete any index in Single Linked List

Delete first data on Single Linked List

Delete the last index of Single Linked List
The code is quite simple rather than add code, I think. Human kind is rather destroying than creating and managing these days.
void DeleteLastIndex()
{
node *temp;
temp=head;
while(temp->nget()!=tail)
{
temp=temp->nget();
}
delete tail;
tail = temp;
tail->nset(NULL);
}
void DeleteAnyIndex(int index)
{
node *temp,*dnew;
temp=head;
dnew=head;
int i=0;
for(i=0;i<index;i++)
{
temp=temp->nget();
}
for(i=0;i<x+1;i++)
{
dnew=dnew->nget();
}
temp->nset(dnew->nget());
delete dnew;
}
void DeleteFront()
{
node *temp;
temp=head;
head=head->nget();
delete temp;
}
I think this code should works fine…. I think, LoL.
Popularity: 51% [?]



