質問編集履歴
1
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,132 +1,6 @@
|
|
1
1
|
```ここに言語を入力
|
2
2
|
|
3
|
-
#include <iostream>
|
4
|
-
|
5
|
-
using namespace std;
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
class Cell {
|
10
|
-
|
11
|
-
private:
|
12
|
-
|
13
|
-
int data;
|
14
|
-
|
15
|
-
Cell *next;
|
16
|
-
|
17
|
-
public:
|
18
|
-
|
19
|
-
Cell(int d, Cell *n = NULL) {
|
20
|
-
|
21
|
-
data = d;
|
22
|
-
|
23
|
-
next = n;
|
24
|
-
|
25
|
-
}
|
26
|
-
|
27
|
-
friend class List;
|
28
|
-
|
29
|
-
};
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
class List {
|
34
|
-
|
35
|
-
private:
|
36
|
-
|
37
|
-
Cell *head;
|
38
|
-
|
39
|
-
public:
|
40
|
-
|
41
|
-
List() {
|
42
|
-
|
43
|
-
head = NULL;
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
~List() {
|
48
|
-
|
49
|
-
while (head != NULL)
|
50
|
-
|
51
|
-
removeFirst();
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
void addFirst(int data) {
|
58
|
-
|
59
|
-
head = new Cell(data, head); }
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
void removeFirst() {
|
64
|
-
|
65
|
-
if (head == NULL)
|
66
|
-
|
67
|
-
return;
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
Cell *removed = head;
|
72
|
-
|
73
|
-
head = head->next;
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
delete removed;
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
void print() {
|
84
|
-
|
85
|
-
for (Cell *p = head; p != NULL; p = p->next)
|
86
|
-
|
87
|
-
cout << p->data;
|
88
|
-
|
89
|
-
cout << endl;
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
void addLast(int data);
|
94
|
-
|
95
|
-
void removeLast();
|
96
|
-
|
97
|
-
};
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
void List::addLast(int data) {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
if (head == NULL)
|
106
|
-
|
107
|
-
head = new Cell(data, head);
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
Cell *p;
|
112
|
-
|
113
|
-
for (p = head; p->next != NULL; p = p->next){}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
Cell *last = new Cell(data, NULL);
|
120
|
-
|
121
|
-
p->next = last;
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
void List::removeLast() { //
|
3
|
+
void List::removeLast() { // 実現できない関数!!
|
130
4
|
|
131
5
|
|
132
6
|
|