回答編集履歴
3
コード修正
answer
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
- while(HT[key]->next != NULL){
|
27
27
|
+ while(lastCell->next != NULL){
|
28
28
|
- HT[key] = HT[key]->next;
|
29
|
-
+ lastCell =
|
29
|
+
+ lastCell = lastCell->next;
|
30
30
|
}
|
31
31
|
|
32
32
|
newcell->next = NULL;
|
2
コード追記
answer
CHANGED
@@ -11,4 +11,29 @@
|
|
11
11
|
while (HT[key]->next != NULL) {
|
12
12
|
HT[key] = HT[key]->next; // ここ
|
13
13
|
}
|
14
|
-
```
|
14
|
+
```
|
15
|
+
---
|
16
|
+
書き換えたいのは`HashTable[0]`~`HashTable[9]`の末尾の`NULL`になっている`next`でしょう?
|
17
|
+
```diff
|
18
|
+
void add_hash_struct(CELL **HT,int x)
|
19
|
+
{
|
20
|
+
CELL *newcell = new CELL;
|
21
|
+
|
22
|
+
int key;
|
23
|
+
key = Hash(x);
|
24
|
+
|
25
|
+
+ CELL* lastCell = HT[key];
|
26
|
+
- while(HT[key]->next != NULL){
|
27
|
+
+ while(lastCell->next != NULL){
|
28
|
+
- HT[key] = HT[key]->next;
|
29
|
+
+ lastCell = last->next;
|
30
|
+
}
|
31
|
+
|
32
|
+
newcell->next = NULL;
|
33
|
+
- HT[key]->next = newcell;
|
34
|
+
+ lastCell->next = newcell;
|
35
|
+
newcell->data = x;
|
36
|
+
}
|
37
|
+
```
|
38
|
+
|
39
|
+
`show_hash_struct`でも`HashTable[0]`~`HashTable[9]`を書き換えてしまっていますが…
|
1
文言修正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
`add_hash_struct()`で`HashTable`を書き換えてしまっているので、
|
1
|
+
`add_hash_struct()`で`HT[key]`つまり`HashTable[key]`を書き換えてしまっているので、
|
2
2
|
`HashTable[0]`~`HashTable[9]`それぞれに対して2回以上追加した場合、最後の2つしか表示されません。
|
3
3
|
```
|
4
4
|
void add_hash_struct(CELL** HT, int x)
|