From 2b55842c2636542f6df63792111073a3cfea0962 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 2 Mar 2021 22:52:33 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=80?= =?UTF-8?q?=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B5=D0=B4=D1=8C?= =?UTF-8?q?=D0=BC=D0=BE=D0=B9=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=81=D0=B2=D1=8F=D0=B7=D0=BD=D1=8B=D0=BC=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/task7.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 list/task7.cpp (limited to 'list/task7.cpp') 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 +#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; + +} -- cgit v1.2.3