summaryrefslogtreecommitdiff
path: root/list/task7.cpp
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-03-18 17:04:18 +0400
committerAndrew <saintruler@gmail.com>2021-03-18 17:04:18 +0400
commit6a4c782f6a0f0146e8ff08be4f1d211b7f3aa691 (patch)
treee43e0a7373d4df905dc75fe761cc2b5c25deefe7 /list/task7.cpp
parent1a6ce2019d2b5e63944b7e345df5010312dc8691 (diff)
Исправил 7 задачу в списках
Diffstat (limited to 'list/task7.cpp')
-rw-r--r--list/task7.cpp35
1 files changed, 16 insertions, 19 deletions
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()