Thread: What are steps to delete node

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    81

    What are steps to delete node

    I want to delete any node in my list I am trying to make function that can delete any node and I have no idea how to do it.

    Code:
    #include<stdio.h>#include<stdlib.h> 
     
     
    struct node{
      int Number;
      struct node *next;
    };
     
     
    struct node* newNode(int number, struct node *next) {
        struct node *new = malloc(sizeof(*new));
               new->Number = number;
               new->next = next;
        return new;
    }
     
     
    void show(struct node *head){
         struct node *c;
         c = head;
         while (c!=NULL){
               printf("%d\n",c->Number);
               c = c->next;
               }
      
         }
          
    int main (void ) {
       struct node *head = NULL;  
       
    head = newNode(10, head);
    head = newNode(20, head);
    head = newNode(30, head);
    show(head);
          
        return 0;
    }
    Last edited by vajra11; 11-12-2019 at 08:16 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Draw on paper a singly linked list with say, 4 nodes. Pick a node and think about how you might go about doing it. Pick another node, say the first and last and go through how you would delete it. Try drawing linked lists with just one or two nodes and do the same.

    When you have gone through this exercise, you would have a good idea how to write code to delete a node from a singly linked list.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    308
    Or if you don't wanna do any of the above as @laserlight says and just want to get stuff done for hw, which is a bad thing if you wanna be a 'good' programmer and I recommend not to, hit google up and look at code written by someone else. I mean, seriously, your problem is not even a problem. Use sometime at the least to write down stuff on how you expect your program to behave, implement it, and then if everything falls apart though your thought process is right, come on here (or any other programming forum) and ask a question. You haven't written any code, not from what I can see, that implements or at-least tries to do what you want. No one here, none that I know, is going to sit and write your code for you...

    Post code relevant to your problem!

    How To Ask Questions The Smart Way

    > I have no idea how to do it.

    Give us proof that you at-least tried in the first place! Show us failure so we know you are interested enough to try to take a programming task on your own. You don't try and learn to run without learning how to walk!
    Last edited by Zeus_; 11-15-2019 at 11:10 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