I am trying to delete Nodes from a given point but I am stuck on how to delete the last node. Nodes other than tail can be deleted by swapping the values and changing the links. My Code:
#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
Node(int x)
{
data = x;
next = NULL;
}
};
void appointNULL(Node *point)
{
point = NULL;
}
int main()
{
Node *head = new Node(10);
head->next = new Node(20);
appointNULL(head->next);
cout<<head->next->data;
}
Output:
20
when I tried to print it came out same without any change?
what am I doing wrong?