My list contain with three nodes I want to delete new node. I do not understand how to delete new node
I want this output 123 13
Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int n;
struct node *next;
}node;
int main()
{
node *current = NULL;
node *new = NULL;
node *last = NULL;
node *head = NULL;
current = malloc(sizeof(current));
new = malloc(sizeof(new));
last = malloc(sizeof(last));
if (current == NULL)
printf ("Memory not Allocated \n");
else
printf ("Memory Allocated \n");
current->n = 1;
current->next = new;
new->n = 2;
new->next= last;
last->n = 3;
last->next= NULL;
free(new);
for (head = current; head != NULL; head = head->next)
{
printf("%d\n", head->n);
}
return 0;
}
output
14090432
14104256
14093800
14095320
garbage value