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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
1 #include <stdio.h>
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
2
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
3 #include "../context.h"
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
4
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
5 // extern enum Relational compare(struct Node* node1, struct Node* node2);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
9
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
10 Tree* createRedBlackTree(struct Context* context) {
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
11 struct Tree* tree = new Tree();
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
12 struct RedBlackTree* redBlackTree = new RedBlackTree();
418
a74bec89c198 generate main
mir3636
parents: 415
diff changeset
13 tree->tree = (union Data*)redBlackTree;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
14 redBlackTree->root = NULL;
415
eec6553a2aa6 fix redblacktree
mir3636
parents: 338
diff changeset
15 redBlackTree->nodeStack = (union Data*)createSingleLinkedStack(context);
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
16
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
17 tree->put = C_putRedBlackTree;
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
18 // tree->get = C_getRedBlackTree;
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
19 // tree->remove = C_removeRedBlackTree;
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
20 // tree->clear = C_clearRedBlackTree;
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
21 return tree;
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
22 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
56 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
65 // __code getRedBlackTree(struct RedBlackTree* tree, __code next(...)) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
66 // if (tree->root) {
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
67 // tree->current = tree->root;
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
68 // goto insertRBTree();
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
69 // // goto deleteRBTree();
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
70 // }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
71 //
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
72 // goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
73 // }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
87 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
88
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
104 goto nodeStack->pop(nodeStack,insertBalance);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
107 goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
108 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
109 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
131 }else{
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
132 goto nodeStack->pop(nodeStack,insertBalance);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
133 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
134 }
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
137
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
150 goto nodeStack->pop(nodeStack,insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
151
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
164 goto nodeStack->pop(nodeStack,insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
165
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
166 }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
167 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
182 goto nodeStack->pop(nodeStack,insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
183
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
184 } else if (current->color == Black && current->right->color == Red && current->right->left->color == Red){
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
197 goto nodeStack->pop(nodeStack,insertBalance);
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
198
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
199 } else {
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
200 printf("unkwon error : __code insertBalanceRight()");
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
201 goto next(...);
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
202 }
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
203 }
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
204
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
205 // insertion code end
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
206
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
207
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
208
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
255
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
256
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
257 /* __code deleteNodeReplace(){ */
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
263
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
264
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
265 /* } */
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
266
446
41a6f8482374 fix RedBlackTree.cbc Insert, printTree. but occur error
ryokka
parents: 445
diff changeset
267 /* } */
445
f02bd096af64 fix RedBlackTree.cbc Insertion
ryokka
parents: 426
diff changeset
268
273
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
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
08d0f920dad2 add RedBlackTree.cbc
mir3636
parents:
diff changeset
274