回答編集履歴

3

コード修正

2021/07/04 13:35

投稿

SHOMI
SHOMI

スコア4079

test CHANGED
@@ -54,7 +54,7 @@
54
54
 
55
55
  - HT[key] = HT[key]->next;
56
56
 
57
- + lastCell = last->next;
57
+ + lastCell = lastCell->next;
58
58
 
59
59
  }
60
60
 

2

コード追記

2021/07/04 13:35

投稿

SHOMI
SHOMI

スコア4079

test CHANGED
@@ -25,3 +25,53 @@
25
25
  }
26
26
 
27
27
  ```
28
+
29
+ ---
30
+
31
+ 書き換えたいのは`HashTable[0]`~`HashTable[9]`の末尾の`NULL`になっている`next`でしょう?
32
+
33
+ ```diff
34
+
35
+ void add_hash_struct(CELL **HT,int x)
36
+
37
+ {
38
+
39
+ CELL *newcell = new CELL;
40
+
41
+
42
+
43
+ int key;
44
+
45
+ key = Hash(x);
46
+
47
+
48
+
49
+ + CELL* lastCell = HT[key];
50
+
51
+ - while(HT[key]->next != NULL){
52
+
53
+ + while(lastCell->next != NULL){
54
+
55
+ - HT[key] = HT[key]->next;
56
+
57
+ + lastCell = last->next;
58
+
59
+ }
60
+
61
+
62
+
63
+ newcell->next = NULL;
64
+
65
+ - HT[key]->next = newcell;
66
+
67
+ + lastCell->next = newcell;
68
+
69
+ newcell->data = x;
70
+
71
+ }
72
+
73
+ ```
74
+
75
+
76
+
77
+ `show_hash_struct`でも`HashTable[0]`~`HashTable[9]`を書き換えてしまっていますが…

1

文言修正

2021/07/04 13:33

投稿

SHOMI
SHOMI

スコア4079

test CHANGED
@@ -1,4 +1,4 @@
1
- `add_hash_struct()`で`HashTable`を書き換えてしまっているので、
1
+ `add_hash_struct()`で`HT[key]`つまり`HashTable[key]`を書き換えてしまっているので、
2
2
 
3
3
  `HashTable[0]`~`HashTable[9]`それぞれに対して2回以上追加した場合、最後の2つしか表示されません。
4
4