changing address of a pointer array's data

Go To


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.

2012-04-04 18:59
by ghostfk
There is a semicolon missing on line 42 - wildplasser 2012-04-04 19:06
could you paste some code of what you have done till now and where you'r facing a problem - keety 2012-04-04 19:08


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:

children_nodes[0] = children_nodes[2];
children_nodes[2] = 0;
2012-04-04 19:29
by Karl Bielefeldt