Commit c1febd5 Mengyi Zhou
committed
1 parent c59ff1e commit c1febd5 Copy full SHA for c1febd5
File tree 1 file changed +19
-4
lines changed
homework/src/main/java/com/offline/training/homework/hw6/dict
1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -129,13 +129,19 @@ public void insert(int key, Tree234Node node) {
129
129
return ;
130
130
}
131
131
132
- if (key < targetNode .key1 ) {
132
+ if (key < targetNode .key1 ) {
133
133
targetNode .key3 = targetNode .key2 ;
134
134
targetNode .key2 = targetNode .key1 ;
135
135
targetNode .key1 = key ;
136
+ } else if (key == targetNode .key1 ) {
137
+ return ;
136
138
} else if (targetNode .keys == 1 || key < targetNode .key2 ){
137
139
targetNode .key3 = targetNode .key2 ;
138
140
targetNode .key2 = key ;
141
+ } else if (key == targetNode .key2 ) {
142
+ return ;
143
+ } else if (key == targetNode .key3 ) {
144
+ return ;
139
145
} else {
140
146
targetNode .key3 = key ;
141
147
}
@@ -184,9 +190,6 @@ private Tree234Node split(Tree234Node node) {
184
190
return root ;
185
191
}
186
192
187
- if (node .parent .isFull ())
188
- split (node .parent );
189
-
190
193
// here parent is guaranteed to be not full
191
194
Tree234Node parent = node .parent ;
192
195
switch (parent .keys ) {
@@ -372,8 +375,20 @@ public static void main(String[] args) {
372
375
t .testHelper ("(((1 4)7(11 16))22((23)28(37 49)))50(((51)60(66)75" +
373
376
"(80 81))84((86)95(99 100)))" );
374
377
378
+ testDuplicate (t );
379
+
375
380
System .out .println ("\n Final tree:" );
376
381
t .printTree ();
377
382
}
378
383
384
+ private static void testDuplicate (Tree234 t ) {
385
+ String origin = t .toString ();
386
+ System .out .println ("\n Duplicating 80, 50, 37, 1." );
387
+ t .insert (80 );
388
+ t .insert (50 );
389
+ t .insert (37 );
390
+ t .insert (1 );
391
+ t .testHelper (origin );
392
+ }
393
+
379
394
}
You can’t perform that action at this time.
0 commit comments