Thread: I want to delete node

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    81

    I want to delete node

    I tried to delete the second node in list

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    struct Node
    {
      int data;
      struct Node *next;
    };
      int main()
    {
      struct Node* head = NULL;
      struct Node* second = NULL;
      struct Node* third = NULL;
    
      head  = (struct Node*)malloc(sizeof(struct Node));
      second = (struct Node*)malloc(sizeof(struct Node));
      third  = (struct Node*)malloc(sizeof(struct Node));
     
      head->data = 1;     
      printf(" %d ", head->data);
      head->next = second; 
     
      second->data = 2;     
      printf(" %d ", second->data);
      
      second->next = third;
      
      free(second);
     
      third->data = 3;   
      printf(" %d ", third->data);
      third->next = NULL;
    
      return 0;
    }
    1 2 3

    free(second);

    but It doesn't delete
    Last edited by vajra11; 11-17-2019 at 06:25 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. delete last node
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 05-02-2007, 08:08 AM
  2. cant get this delete node working
    By qubit67 in forum C Programming
    Replies: 3
    Last Post: 04-25-2007, 02:36 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