I am trying to implement a search algorithm,it needs a tree with four(NOTE n=4) nodes.Is the struct declaration correct for array of structure pointers??You see the main idea is start with the 'cur' node.Then take a new 'temp' node. Copy the contents of 'cur->state' into 'temp->state' then perform the 'res' operation.The result of which is stored in the 'cur->action[i]' node for every 'n' iteration.I am getting a memory leak ,I can only do one iteration.The program terminates at the 'temp' declaration during the second iteration.Please help me am I missing something??I have allocated and freed 'temp' then why the memory leak??Please ignore the other parts.
That site is not loading and I don't know how to use it.Can u tell the problem with my code.I am sure I must be making a very obvious mistake.Is the format of the struct and the way it is called correct??I am missing something here...
> What alternative would you suggest?
making `states' a container.
copy constructor
std::copy()
1 2
tree *temp=new tree;
memcpy( temp->state,cur->state,sizeof(cur->state)*nstates);
¿is `temp->state' initialized?
1 2
cur->action[i]=temp;
delete[] temp;
first, it should be delete temp;, as you had allocated with new
second, note how those two line may be swapped without altering the meaning. ¿why are you storing an invalid pointer?