I am trying to delete current node in list
after deleting current list should print 4, 3, 2, 1
but program print strange value. How to delete current node
Code:
#include<stdio.h>#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
void delete( struct node *current)
{
if (current != NULL)
{
free(current);
}
}
void instert( struct node **current, int value)
{
struct node *new = malloc(sizeof(struct node));
if ( new != NULL)
{
new-> data = value;
new -> next = *current;
*current = new;
}
}
void List(struct node *current)
{
while (current !=NULL)
{
printf("%d ", current -> data);
current = current -> next;
}
}
int main ()
{
struct node *head = NULL;
instert(&head, 1);
instert(&head, 2);
instert(&head, 3);
instert(&head, 4);
instert(&head, 5);
List(head);
delete (head);
printf("\n");
List(head);
return 0;
}
output
Code:
7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 7217968 7209152 7222088 ^C