void deleteNode(int num)
{
int pos=1;
node *temp, *pre;
temp=start; // assigning start node address to temp
if(temp==NULL) // Checking list is empty?
{
cout<<"*************List Is empty************";
return;
}
if(num==pos) // If user want to delte first node
{
if(temp->next==NULL) // checking first node is last?
{
start=NULL; // List Will Become Empty
cout<<"There Was Only One Node ... Now List Is Empty";
return;
}
start=temp->next;
return;
}
while (temp->next!=NULL)
{
pre=temp;
temp=temp->next;
pos++;
if(pos==num)
{
if(temp->next=NULL)
{
pre->next=NULL;
cout<<"You Deleted Last Node Of Your List..."<<endl;
return;
}
else
{
pre->next=temp->next;
return;
}
}
}
}
I'm using C++
Here I am not deleting the node but removing its address from list. I will use the delete function after this, still I am understanding linking of nodes.