From 6a4c782f6a0f0146e8ff08be4f1d211b7f3aa691 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 18 Mar 2021 17:04:18 +0400 Subject: =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=207=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D1=83=20=D0=B2=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list/Makefile | 5 ++++- list/task7.cpp | 35 ++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'list') diff --git a/list/Makefile b/list/Makefile index 4a9376f..105500b 100644 --- a/list/Makefile +++ b/list/Makefile @@ -21,4 +21,7 @@ test15: task15 @printf "Answer: 1\n" clean: - rm task.out + rm -f task.out *.zip + +archive: clean + zip archive.zip *.cpp *.h diff --git a/list/task7.cpp b/list/task7.cpp index 600c9a5..4068a6f 100644 --- a/list/task7.cpp +++ b/list/task7.cpp @@ -5,32 +5,29 @@ 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; - + int size = 0; list *cur = h; - while (cur) + while (cur) { - if (cur->inf < x) - push(res_h, res_t, cur->inf); - else - push(tmp_h, tmp_t, cur->inf); - + size++; cur = cur->next; } - cur = tmp_h; - while (cur) + cur = h; + for (int i = 0; i < size; i++) { - push(res_h, res_t, cur->inf); - cur = cur->next; + if (cur->inf >= x) + { + push(h, t, cur->inf); + list *tmp = cur; + cur = cur->next; + del_node(h, t, tmp); + } + else + { + cur = cur->next; + } } - - h = res_h; - t = res_t; } int main() -- cgit v1.2.3