MRehanQadri 0 Junior Poster in Training

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";
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.