Hello
I'm coding an algorithm based on genetic programming with tree structures in C. I implemented tree structure using recursive structure pointers **The traditional way**
struct tree
{
int val;
tree *left;
tree *right;
};
tree a[10];
tree b[20];
void main()
{
generate (); // this generates me 10 random trees and places them in a
b[0] = a[0]; // copies val, left and right correspondingly
// though b[0].left and a[0].left are stored separately, both point to the same location
// if i change a[0].left->val , it correspondingly reflects when i access b[0].left->
// This is not intended for my application when i let crossover and mutation play over // my trees.
// So i must (something like) clone trees to have seperate copies.
And could not sort out a way to clone my trees (binary trees)
Any kind of help is appreciated.