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 wrap: on
line diff
--- 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;
 }
--- 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) {
--- 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 */