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