Mercurial > hg > GearsTemplate
annotate src/parallel_execution/RedBlackTree.cbc @ 446:41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
author | ryokka |
---|---|
date | Wed, 29 Nov 2017 22:13:05 +0900 |
parents | f02bd096af64 |
children | 1432d924c472 |
rev | line source |
---|---|
273 | 1 #include <stdio.h> |
2 | |
3 #include "../context.h" | |
4 | |
445 | 5 // extern enum Relational compare(struct Node* node1, struct Node* node2); |
6 | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
7 extern enum Relational compare(struct Node* node1, struct Node* node2); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
8 |
273 | 9 |
10 Tree* createRedBlackTree(struct Context* context) { | |
11 struct Tree* tree = new Tree(); | |
12 struct RedBlackTree* redBlackTree = new RedBlackTree(); | |
418 | 13 tree->tree = (union Data*)redBlackTree; |
273 | 14 redBlackTree->root = NULL; |
415 | 15 redBlackTree->nodeStack = (union Data*)createSingleLinkedStack(context); |
445 | 16 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
17 tree->put = C_putRedBlackTree; |
445 | 18 // tree->get = C_getRedBlackTree; |
273 | 19 // tree->remove = C_removeRedBlackTree; |
20 // tree->clear = C_clearRedBlackTree; | |
21 return tree; | |
22 } | |
23 | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
24 __code printTree(struct RedBlackTree* tree) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
25 printTree1(tree); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
26 printf("\n"); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
27 } |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
28 |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
29 __code printTree1(struct RedBlackTree* tree) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
30 struct Node* node = tree->current; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
31 if (node == NULL) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
32 printf("Leaf"); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
33 } else { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
34 printf("key = %d (", node->key); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
35 printTree1(node->right); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
36 printf("), ("); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
37 printTree1(node->left); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
38 printf(")"); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
39 } |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
40 } |
273 | 41 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
42 __code putRedBlackTree(struct Node* node, struct RedBlackTree* tree) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
43 struct Node* newNode = &ALLOCATE(context, Node)->Node; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
44 struct Node* root = tree->root; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
45 printTree((tree->root)); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
46 tree->newNode = newNode; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
47 // tree->root = newNode; // this should done at stackClear |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
48 tree->parent = NULL; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
49 if (root) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
50 tree->current = root; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
51 // tree->result = compare(tree->current, node); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
52 goto insertRBTree(newNode, tree); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
53 } |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
54 print("error : __code putRedBlackTree"); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
55 goto next(...); |
273 | 56 } |
57 | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
58 //__code stackClear(struct RedBlackTree* tree, struct Stack* nodeStack, __code next(...)) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
59 // tree->current = 0; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
60 // nodeStack->stack = tree->nodeStack; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
61 // nodeStack->next = next; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
62 // goto meta(context, tree->nodeStack->clear); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
63 //} |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
64 |
445 | 65 // __code getRedBlackTree(struct RedBlackTree* tree, __code next(...)) { |
66 // if (tree->root) { | |
67 // tree->current = tree->root; | |
68 // goto insertRBTree(); | |
69 // // goto deleteRBTree(); | |
70 // } | |
71 // | |
72 // goto next(...); | |
73 // } | |
273 | 74 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
75 __code insertRBTree(struct Node* node, struct RedBlackTree* tree) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
76 tree->current = node; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
77 struct Stack* nodeStack = tree->nodeStack; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
78 |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
79 if (tree->root == null){ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
80 tree->root = tree->current; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
81 tree->root->color = Black; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
82 goto next(...); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
83 }else{ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
84 goto searchInsertLocatetion(newNode, nodeStack, tree); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
85 } |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
86 |
273 | 87 } |
88 | |
89 | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
90 __code searchInsertLocation(struct Node* node, struct Stack* nodeStack, struct RedBlackTree* tree) { |
445 | 91 struct Stack* nodeStack = tree->nodeStack; |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
92 struct Node* trace = tree->current; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
93 |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
94 |
273 | 95 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
96 // i think faster "compare tree->current, node" than "switch case EQ, LT, RT" |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
97 if (tree->current > node || tree->current < node) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
98 goto nodestack->push(nodeStack,trace, searchInsertLocation); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
99 } else if (tree->current == node) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
100 printf("alady member this node : __code searchInsertLocation()"); |
445 | 101 goto next(...); |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
102 } else if (tree->current == null){ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
103 tree->current = node; |
445 | 104 goto nodeStack->pop(nodeStack,insertBalance); |
105 }else{ | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
106 printf("$insert value tree : __code searchInsertLocation()"); |
445 | 107 goto next(...); |
108 } | |
273 | 109 } |
110 | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
111 __code insertBalance(struct RedBlackTree* tree, struct Node* nodeStack, struct Node* node){ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
112 tree->current = nodeStack->data; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
113 |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
114 // exit insertion code |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
115 if (tree->current == tree->root) { |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
116 tree->current->color = Black; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
117 printTree(((union Data* ) (tree->root))); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
118 //printTree |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
119 goto next(...); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
120 } |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
121 |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
122 //current color eq Red |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
123 if (current->color == Red) |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
124 goto nodeStack->pop(nodeStack, trace, insertBalance); |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
125 |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
126 // current color eq Black |
445 | 127 if (current->left->left || current->left->right){ |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
128 goto insertBalanceLeft(tree,nodeStack); |
445 | 129 }else if (current->right->left || current->right->right){ |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
130 goto insertBalanceRight(tree,nodeStack); |
445 | 131 }else{ |
132 goto nodeStack->pop(nodeStack,insertBalance); | |
133 } | |
273 | 134 } |
135 | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
136 __code insertBalanceLeft(struct RedBlackTree* tree, struct Node* nodeStack, struct Node* node){ |
273 | 137 |
445 | 138 if (current->color == Black && current->left->color == Red && current->left->left->color == Red){ |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
139 struct Node* tmpCurrent = tree->current; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
140 struct Node* tmpLeft = tree->current->left; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
141 struct Node* tmpLeftLeft = tree->current->left->left; |
273 | 142 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
143 tree->current = tmpLeft; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
144 tree->current->right = tmpCurrent; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
145 tree->current->left = tmpLeftLeft; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
146 tree->current->right->left = tmpLeft->right; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
147 tree->current->color = Red; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
148 tree->current->left->color = Black; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
149 tree->current->right->color = Black; |
445 | 150 goto nodeStack->pop(nodeStack,insertBalance); |
273 | 151 |
445 | 152 } else if(current->color == Black && current->left->color == Red && current->left->right->color == Red){ |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
153 struct Node* tmpCurrent = tree->current; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
154 struct Node* tmpLeft = tree->current->left; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
155 struct Node* tmpLeftRight = tree->current->left->right; |
273 | 156 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
157 tree->current = tmpLeft; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
158 tree->current->right = tmpCurrent; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
159 tree->current->left = tmpLeftRight; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
160 tree->current->right->left = tmpLeft->left; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
161 tree->current->color = Red; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
162 tree->current->left->color = Black; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
163 tree->current->right->color = Black; |
445 | 164 goto nodeStack->pop(nodeStack,insertBalance); |
273 | 165 |
445 | 166 } |
167 } | |
273 | 168 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
169 __code insertBalanceRight(struct RedBlackTree* tree, struct Node* nodeStack, struct Node* node){ |
445 | 170 if (current->color == Black && current->right->color == Red && current->right->right->color == Red){ |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
171 struct Node* tmpCurrent = tree->current; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
172 struct Node* tmpRight = tree->current->right; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
173 struct Node* tmpRightRight = tree->current->right->right; |
273 | 174 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
175 tree->current = tmpRight; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
176 tree->current->left = tmpCurrent; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
177 tree->current->Right = tmpRightRight; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
178 tree->current->left->right = tmpRight->left; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
179 tree->current->color = Red; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
180 tree->current->left->color = Black; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
181 tree->current->right->color = Black; |
445 | 182 goto nodeStack->pop(nodeStack,insertBalance); |
273 | 183 |
445 | 184 } else if (current->color == Black && current->right->color == Red && current->right->left->color == Red){ |
273 | 185 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
186 struct Node* tmpCurrent = tree->current; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
187 struct Node* tmpRight = tree->current->right; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
188 struct Node* tmpRightLeft = tree->current->right->left; |
273 | 189 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
190 tree->current = tmpRight; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
191 tree->current->right = tmpCurrent; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
192 tree->current->left = tmpRightLeft; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
193 tree->current->left->right = tmpRight->right; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
194 tree->current->color = Red; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
195 tree->current->left->color = Black; |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
196 tree->current->right->color = Black; |
445 | 197 goto nodeStack->pop(nodeStack,insertBalance); |
273 | 198 |
445 | 199 } else { |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
200 printf("unkwon error : __code insertBalanceRight()"); |
445 | 201 goto next(...); |
202 } | |
203 } | |
273 | 204 |
445 | 205 // insertion code end |
273 | 206 |
445 | 207 |
208 | |
273 | 209 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
210 /* __code deleteRBTree(struct RedBlackTree newNode, struct RedBlackTree* tree) { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
211 /* tree->current = tree->root; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
212 /* goto deleteLocate; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
213 /* } */ |
273 | 214 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
215 /* __code deleteLocate(struct Node* node, struct Stack* nodeStack, struct RedBlackTree* tree) { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
216 /* /\* check delete node locate and push route node *\/ */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
217 /* struct Stack* nodeStack = tree->nodeStack; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
218 /* struct Node* trace = tree->current; */ |
273 | 219 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
220 /* if (tree->current > node) { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
221 /* goto nodeStack->push(nodeStack,trace,deleteLocate); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
222 /* } else if (tree->current < node) { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
223 /* goto nodeStack->push(trace,deleteLocate); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
224 /* } else if (tree->current == node) { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
225 /* // trace = tree->current; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
226 /* goto deleteNode(struct Stack* nodeStack, struct RedBlackTree* tree,struct Node* trace); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
227 /* // goto nodeStack->push(trace,deleteNode); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
228 /* } else if (tree->current == null){ */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
229 /* printf("No member Delete node (__code deleteLocate)"); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
230 /* goto next(...); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
231 /* } else { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
232 /* printf("Error,__code deleteLocate"); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
233 /* goto next(...); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
234 /* } */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
235 /* } */ |
273 | 236 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
237 /* __code deleteNode(struct Node* node, struct Stack* nodeStack, struct RedBlackTree* tree) { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
238 /* struct Stack* nodeStack = tree->nodeStack; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
239 /* struct Node* replaceNode = nodeStack->data; */ |
273 | 240 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
241 /* if(replaceNode->right == null){ */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
242 /* tree->current = replaceNode; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
243 /* tree->current = tree->current->left; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
244 /* goto deleteUnbalance(nodeStack,replaceNode); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
245 /* }else if(replaceNode->left == null){ */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
246 /* tree->current = replaceNode; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
247 /* tree->current = tree->current->right; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
248 /* goto deleteUnbalance(nodeStack,replaceNode); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
249 /* //goto deleteNodeReplaceNull(); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
250 /* }else{ */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
251 /* // goto nodeStack->push(nodeStack,replaceNode,deleteNodeReplace); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
252 /* goto deleteNodeReplace(nodeStack,replaceNode); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
253 /* } */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
254 /* } */ |
273 | 255 |
256 | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
257 /* __code deleteNodeReplace(){ */ |
273 | 258 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
259 /* if (replaceNode->left != null){ */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
260 /* replaceNode = replaceNode->left; */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
261 /* goto deleteNodeReplace(); */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
262 /* }else if(){ */ |
273 | 263 |
264 | |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
265 /* } */ |
445 | 266 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
267 /* } */ |
445 | 268 |
273 | 269 |
446
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
270 /* __code deleteUnbalance() { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
271 /* if () { */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
272 /* } */ |
41a6f8482374
fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents:
445
diff
changeset
|
273 /* } */ |
273 | 274 |