# HG changeset patch # User meillo@marmaro.de # Date 1204450195 -3600 # Node ID 22305a6e128d342a93b81546b9341db7a00c80aa # Parent 0b82169d412979b56434d25fd7c5fd88ffd3df3f added deep copy and fixed so node times diff -r 0b82169d4129 -r 22305a6e128d actions.c --- a/actions.c Sat Mar 01 21:49:41 2008 +0100 +++ b/actions.c Sun Mar 02 10:29:55 2008 +0100 @@ -87,17 +87,9 @@ unsigned char action_times(struct Node* node) { - struct Node* tp; - struct Node* last; unsigned char i; - tp = node->down; for (i = 0; i < node->value; i++) { - /* FIXME deep copy */ - last = insertLast(node, newNode(tp->name, tp->value)); - if (tp->down != NULL) { - last->down = newNode(tp->down->name, tp->down->value); - } - + insertLast(node, copyTree(node->down)); } return 0; } diff -r 0b82169d4129 -r 22305a6e128d baum.c --- a/baum.c Sat Mar 01 21:49:41 2008 +0100 +++ b/baum.c Sun Mar 02 10:29:55 2008 +0100 @@ -67,6 +67,17 @@ return insert; } +struct Node* copyTree(struct Node* node) { + if (node == NULL) { + return NULL; + } + struct Node* tmp; + tmp = newNode(node->name, node->value); + tmp->down = copyTree(node->down); + tmp->right = copyTree(node->right); + return tmp; +} + /* delete */ void delete(struct Node* node) { diff -r 0b82169d4129 -r 22305a6e128d baum.h --- a/baum.h Sat Mar 01 21:49:41 2008 +0100 +++ b/baum.h Sun Mar 02 10:29:55 2008 +0100 @@ -2,6 +2,7 @@ struct Node* newNode(char* name, unsigned char value); struct Node* insertLast(struct Node* node, struct Node* insert); +struct Node* copyTree(struct Node* node); /* structs */