I have a tree, each node contains an array children nodes (Node *children_nodes), as well as the name (char *node_name) and parent (Node *parent). each of these are dynamic. I want to delete a child node from the *children_nodes array, freeing the memory allocated to it's name and children, (let's pretend we are deleting a child with no children), and move the location of the last child of the list to the location of the one we just deleted. how can I do this without making the last node get changed if I want to use the location it was in.
Example- I have a node with three children, I want to free children_nodes[0]'s allocated memory and put children_nodes[2] in that spot, preferably just making children_nodes[0] point to the node of children_nodes[2] and then making children_nodes[2] point to nothing without messing with the node itself.
It's difficult to tell for sure without seeing some code, but I believe you want a Node** children_nodes
, so you can just do something like this:
free(children_nodes[0]);
children_nodes[0] = children_nodes[2];
children_nodes[2] = 0;