diff options
| author | Andrew <saintruler@gmail.com> | 2021-02-11 00:24:49 +0400 |
|---|---|---|
| committer | Andrew <saintruler@gmail.com> | 2021-02-11 00:24:49 +0400 |
| commit | b3f28bca3da03a81fb7a72f85f563360d4f13b0f (patch) | |
| tree | 2e91e9f7eb85abd59f09c78f905b769b7199bd16 | |
| parent | 17a4c9f6e0380aae2366b33628fae0ef722ec762 (diff) | |
Добавил комментариев.
| -rw-r--r-- | structures/task14.cpp | 4 | ||||
| -rw-r--r-- | structures/task18.cpp | 4 | ||||
| -rw-r--r-- | structures/task25.cpp | 11 |
3 files changed, 14 insertions, 5 deletions
diff --git a/structures/task14.cpp b/structures/task14.cpp index fcd9d63..6804a60 100644 --- a/structures/task14.cpp +++ b/structures/task14.cpp @@ -3,7 +3,7 @@ using namespace std; -void result(queue *&h, queue *&t, queue *&hr, queue *&tr) +void solve(queue *&h, queue *&t, queue *&hr, queue *&tr) { while (h) { @@ -35,7 +35,7 @@ int main() queue *head_res = NULL; queue *tail_res = NULL; - result(head, tail, head_res, tail_res); + solve(head, tail, head_res, tail_res); while (head_res) cout << char(pop(head_res, tail_res)) << " "; cout << endl; diff --git a/structures/task18.cpp b/structures/task18.cpp index fcc0c67..b954bf0 100644 --- a/structures/task18.cpp +++ b/structures/task18.cpp @@ -3,7 +3,7 @@ using namespace std; -void result(queue *&h, queue *&t, queue *&hr, queue *&tr) +void solve(queue *&h, queue *&t, queue *&hr, queue *&tr) { int prev; prev = pop(h, t); @@ -38,7 +38,7 @@ int main() queue *head_res = NULL; queue *tail_res = NULL; - result(head, tail, head_res, tail_res); + solve(head, tail, head_res, tail_res); while (head_res) cout << pop(head_res, tail_res) << " "; cout << endl; diff --git a/structures/task25.cpp b/structures/task25.cpp index fde664c..730e465 100644 --- a/structures/task25.cpp +++ b/structures/task25.cpp @@ -10,15 +10,23 @@ int main() cin >> n; stack *s = NULL; - char* buf = new char[32]; + // Так как в int не помещаются числа длиной более 10 + // знаков, буфера такого размера будет достаточно. + char* buf = new char[16]; for (int i = 0; i < n; i++) { cin >> buf; + + // Если первый элемент буфера -- цифра, то можно считать, что + // в буфере находится число и его нужно преобразовать в int. if ('0' <= buf[0] && buf[0] <= '9') { int i = atoi(buf); push(s, i); } + // Иначе, скорее всего, в буфере находится операция. + // Если первый символ не является допустимой операцией, + // то ничего не происходит. else { switch (buf[0]) @@ -44,6 +52,7 @@ int main() } } + // В результате выполнения выражения в стеке должно остаться одно число. int result = pop(s); cout << "Result = " << result << endl; |