baum

changeset 46:22305a6e128d

added deep copy and fixed so node times
author meillo@marmaro.de
date Sun, 02 Mar 2008 10:29:55 +0100
parents 0b82169d4129
children c31b5bb6d493
files actions.c baum.c baum.h
diffstat 3 files changed, 13 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/actions.c	Sat Mar 01 21:49:41 2008 +0100
     1.2 +++ b/actions.c	Sun Mar 02 10:29:55 2008 +0100
     1.3 @@ -87,17 +87,9 @@
     1.4  
     1.5  
     1.6  unsigned char action_times(struct Node* node) {
     1.7 -	struct Node* tp;
     1.8 -	struct Node* last;
     1.9  	unsigned char i;
    1.10 -	tp = node->down;
    1.11  	for (i = 0; i < node->value; i++) {
    1.12 -		/* FIXME deep copy */
    1.13 -		last = insertLast(node, newNode(tp->name, tp->value));
    1.14 -		if (tp->down != NULL) {
    1.15 -			last->down = newNode(tp->down->name, tp->down->value);
    1.16 -		}
    1.17 -
    1.18 +		insertLast(node, copyTree(node->down));
    1.19  	}
    1.20  	return 0;
    1.21  }
     2.1 --- a/baum.c	Sat Mar 01 21:49:41 2008 +0100
     2.2 +++ b/baum.c	Sun Mar 02 10:29:55 2008 +0100
     2.3 @@ -67,6 +67,17 @@
     2.4  	return insert;
     2.5  }
     2.6  
     2.7 +struct Node* copyTree(struct Node* node) {
     2.8 +	if (node == NULL) {
     2.9 +		return NULL;
    2.10 +	}
    2.11 +	struct Node* tmp;
    2.12 +	tmp = newNode(node->name, node->value);
    2.13 +	tmp->down = copyTree(node->down);
    2.14 +	tmp->right = copyTree(node->right);
    2.15 +	return tmp;
    2.16 +}
    2.17 +
    2.18  
    2.19  /* delete */
    2.20  void delete(struct Node* node) {
     3.1 --- a/baum.h	Sat Mar 01 21:49:41 2008 +0100
     3.2 +++ b/baum.h	Sun Mar 02 10:29:55 2008 +0100
     3.3 @@ -2,6 +2,7 @@
     3.4  
     3.5  struct Node* newNode(char* name, unsigned char value);
     3.6  struct Node* insertLast(struct Node* node, struct Node* insert);
     3.7 +struct Node* copyTree(struct Node* node);
     3.8  
     3.9  
    3.10  /* structs */