回答編集履歴
2
追記
test
CHANGED
@@ -32,11 +32,9 @@
|
|
32
32
|
|
33
33
|
if(current->birthday % 2 == 0){
|
34
34
|
|
35
|
-
Node* del = current;
|
36
|
-
|
37
35
|
*now = current->next;
|
38
36
|
|
39
|
-
delete
|
37
|
+
delete current;
|
40
38
|
|
41
39
|
} else {
|
42
40
|
|
@@ -49,3 +47,63 @@
|
|
49
47
|
}
|
50
48
|
|
51
49
|
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
なんとなく、一応解説
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
```c
|
66
|
+
|
67
|
+
Node keeper;
|
68
|
+
|
69
|
+
keeper.next = head;
|
70
|
+
|
71
|
+
Node* last = &keeper;
|
72
|
+
|
73
|
+
// last は最後に調べた要素
|
74
|
+
|
75
|
+
while(last->next != tail){
|
76
|
+
|
77
|
+
current = last->next;
|
78
|
+
|
79
|
+
if(current->birthday % 2 == 0){
|
80
|
+
|
81
|
+
// currentの誕生日は偶数なので飛ばす
|
82
|
+
|
83
|
+
last->next = current->next;
|
84
|
+
|
85
|
+
delete current;
|
86
|
+
|
87
|
+
// last->nextを調べてないのでlastを更新しない
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
else
|
92
|
+
|
93
|
+
// last->nextを調べたのでlastを更新する
|
94
|
+
|
95
|
+
last = current;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
head = keeper.next;
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
片方向リストは先頭要素を指すダミーを作ってしまうと↑のようになります。
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
よくみると、`last`は`last->next`にしか使ってないのでポインタでどうにかなるってのが提示したソースです。
|
1
コード修正
test
CHANGED
@@ -30,19 +30,19 @@
|
|
30
30
|
|
31
31
|
while(current != tail){
|
32
32
|
|
33
|
-
if(current->birthday % 2 == 0){
|
33
|
+
if(current->birthday % 2 == 0){
|
34
34
|
|
35
|
-
Node* del = current;
|
35
|
+
Node* del = current;
|
36
36
|
|
37
|
-
*now = current->next;
|
37
|
+
*now = current->next;
|
38
38
|
|
39
|
-
delete del;
|
39
|
+
delete del;
|
40
40
|
|
41
|
-
} else {
|
41
|
+
} else {
|
42
42
|
|
43
|
-
now = ¤t->next;
|
43
|
+
now = ¤t->next;
|
44
44
|
|
45
|
-
}
|
45
|
+
}
|
46
46
|
|
47
47
|
current = *now;
|
48
48
|
|