Thread: I need help to delete new node

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    90

    I need help to delete new node

    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

    Last edited by Player777; 01-08-2020 at 01:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I want to delete node
    By vajra11 in forum C Programming
    Replies: 10
    Last Post: 11-21-2019, 05:13 AM
  2. delete last node
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 05-02-2007, 08:08 AM
  3. BST - delete node
    By marrk in forum C Programming
    Replies: 5
    Last Post: 12-20-2006, 10:46 AM
  4. Delete node
    By AmazingRando in forum C Programming
    Replies: 1
    Last Post: 09-23-2003, 04:44 PM
  5. Delete node!!!!!
    By khpuce in forum C Programming
    Replies: 3
    Last Post: 05-31-2003, 06:33 AM

Tags for this Thread