diff options
| author | Andrew <saintruler@gmail.com> | 2021-03-02 22:45:12 +0400 |
|---|---|---|
| committer | Andrew <saintruler@gmail.com> | 2021-03-02 22:45:12 +0400 |
| commit | e413f3fc478da395fab295671b1ccd9f5bdb5b7e (patch) | |
| tree | 9e82529349fc7830388e7bf97ea9338c46975ad9 /list/task4.cpp | |
| parent | b3f28bca3da03a81fb7a72f85f563360d4f13b0f (diff) | |
Добавил решение четвёртой задачи по связным спискам
Diffstat (limited to 'list/task4.cpp')
| -rw-r--r-- | list/task4.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/list/task4.cpp b/list/task4.cpp new file mode 100644 index 0000000..c217664 --- /dev/null +++ b/list/task4.cpp @@ -0,0 +1,42 @@ +#include <iostream> +#include "list.h" + +using namespace std; + +void solve(list *&h, list *&t) +{ + list *cur = h; + while (cur) + { + if (cur->inf % 2 == 0) + { + list *tmp = cur; + cur = cur->next; + del_node(h, t, tmp); + } + else cur = cur->next; + } +} + +int main() +{ + int n; + cout << "n = "; + cin >> n; + + list *head = NULL; + list *tail = NULL; + int x; + for (int i = 0; i < n; i++) + { + cin >> x; + push(head, tail, x); + } + + solve(head, tail); + print(head, tail); + cout << endl; + + return 0; + +} |