If p is a pointer pointing a node to be deleted, then what's wrong in the following code:
cout << "Do you want to delete this record? (y/n) ";
if (getch() == 'y' || getch() == 'Y'){// Delete record.
if (p == *ph){//If first node is to be deleted.
*ph = (*ph)->next;
delete p;
}
else{
a *b = *ph;
while (b->next!=p){
b = b->next;
}//Now b is just before p.
b->next = b->next->next;
delete p;
//p = NULL;
}
system("cls");
}
else
cout << "Another";
}