diff options
Diffstat (limited to 'list/task7.cpp')
| -rw-r--r-- | list/task7.cpp | 35 |
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() |