Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8261603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:27:57+00:00 2026-06-08T03:27:57+00:00

EDIT: Problem: Deleting a node between 2 nodes, and then linking the outer nodes

  • 0

EDIT: Problem: Deleting a node between 2 nodes, and then linking the outer nodes with each other.

After learning and building several quadtrees and octrees, and really liking subdivision, I decided to use subdivision in my server. But, only placing nodes within themselves. My problem is, I cant figure out how to link the previous node, to the next one if the node is in the middle. I am wondering if I am doing this correctly. Below is my code and I comment where the problem area is. Any help would be great!

bool deleteNode ( SOCKET s , client_information_class *prev ) {
          bool return_value = false;
          if ( node[0]->client_socket != s ) {
               if ( node[0]->node != NULL ) {
                    return_value = node[0]->deleteNode ( s , *node );
               } else {
                    cout << endl << "Can not call deleteNode anymore ... Did not find the node to delete ... " << endl;
                    return return_value;
               }
          } else {
               if ( node[0]->client_state == 1 )
                    InterlockedDecrement(&connection_count);
               if ( node[0]->node != NULL ) {          // there is a next node
                    client_information_class **next = node[0]->node;
                    if ( next[0]->node != NULL ) {
                         // problem area
                         cout << endl << "next[0]->node is not null" << endl;
                         prev->node = next[0]->node[0]->node; // ??? I know its wrong
                    } else {
                         // problem area
                         cout << endl << "next[0]->node is null" << endl;
                         prev->node = next[0]->node;  // ??? I know its wrong
                    }
                    delete node;
               } else {                                   // its the last one
                    prev->node = NULL;
                    delete node;
               }
               InterlockedDecrement(&socket_count);
               return_value = true;
          }
          return return_value;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:27:58+00:00Added an answer on June 8, 2026 at 3:27 am

    So if I got your problem right, you have a trouble inserting an item inside a linked list. I really really hope this is the issue, otherwise all the typing I’ve done was totally in vain.

    I didn’t really get all of your code (since it’s a little out of context), but I’ll show you the logic on an example. I will use nodes that have the following structure:

    class Node
    {
    public:
        Node * next_;
        Node * prev_;
        int i;//we need this to tell nodes apart. 
        //And whatever data you want.
    }
    

    So we will make a linked list in which each item has pointers to the previous and the next items. The logic for more complicated structures (like if you have, for example, left + right + child + parent pointers) is the same, the only difference is that you will have to set all of them. It doesn’t really change much.

    So, to construct the list, we will need a couple of constructors that will handle different operations:

    the default constructor to make an empty node:

    Node()//default constructor
    {
        prev_ = nullptr;
        next_ = nullptr;
        i = 0;
    }
    

    a constructor that takes a pointer to the last item in the list, and appends itself to the end of the list:

    Node( Node * prev )//constructor for appending to the end of the list
    {
        prev_ = prev;
        next_ = nullptr;//we append to the end, so there is no "next" element
    prev->next_ = this;
        i = 0;
    }
    

    And finally a constructor to insert in the middle (which, I believe, is what you want):

    Node( Node * prev, Node * next)//Inserting between prev and next nodes
    {
        prev->next_ = this;
        next->prev_ = this;
        this->prev_ = prev;
        this->next_ = next;
        i = 0;
    }
    

    Now we have the full set of instruments to do whatever we want. The one last thing is deleting a node:

    void deleteNode( Node * deleteMe )
    {
        deleteMe->prev_->next_ = deleteMe->next;
        deleteMe->next_->prev_ = deleteMe->prev;
        delete deleteMe;
    }
    

    or, a more readable syntax:

    void deleteNode( Node * deleteMe )
    {
        Node * prevNode = deleteMe->prev_;
        Node * nextNode = deleteMe->next_;
        prevNode->next_ = deleteMe->next;
        nextNode->prev_ = deleteMe->prev;
        delete deleteMe;
    }
    

    let’s make a sample list of, say, 10 elements:

    int main()
    {
        Node * root =  new Node();//the root of the list. it never changes.
        Node * last = root;//The pointer to the last element
        for(int i = 0; i < 10; i++)
        {
            Node * tmp = new Node( last );
            last = tmp;
        }
    }
    

    Here, all the elements in the list are properly linked, and have their i field containing 0 value. Let’s insert another element somewhere in the middle, for example, between the third and the fourth elements:

    Node * thirdNode = root->next_->next_;//I know this sucks, but it's just an example.
    Node * insertMe = new Node(thirdNode, thirdNode->next_);//inserting between the third and the fourth.
    insertMe->i = 9;//this will indicate the one we inserted, since all the others will have this as 0.
    

    Now we can easily check if the insertion went correctly. Let’s type all the element’s data:

    for( Node * it = root; it!= last; it = it->next_)
    {
        std::cout << it->i << " ";
    }
    

    The result will be 0 0 0 9 0 0 0 0 0 0 0.

    Finally, let’s delete the just-inserted node:

    deleteNode( insertMe );
    

    If you will not output the values in the same vay, you will see only zeroes, which means the node was successfully deleted.

    If you have more pointers in your nodes, all you have to do is to handle them properly in the same way. Another hint for you is to avoid constructions like this->next->next->prev. It is hard to tell that you are referring to the “prev” pointer of the element that is third from the current one. Instead, use something like:

    Node * target = this->next->next;//easy to read
    

    or maybe

    Node * target = this;
    for(int i = 0; i < 5; i++)
        target = target->next;
    

    and then work with the pointer you got.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
[EDIT: Problem solved. Please see my answer below.] In my app I call the
Ok, I'll put the code first hopefully to make it clearer. ***Edit: Problem is
Edit: This problem was down to me passing the wrong view to the Touch
[Edit: This problem applies only to 32-bit systems. If your computer, your OS and
Edit 1: Uninstalled & Reinstalled Edit 2: Same problem. Seriously? Yes. I am having
Most of you probably know the following problem: You edit an HTML, view the
Edit: I fixed the problem by just starting from scratch. Sorry to waste y'alls
EDIT I have finally figured out the problem i have been having on my
edit: I was trying to solve a spoj problem. Here is the link to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.