From e413f3fc478da395fab295671b1ccd9f5bdb5b7e Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 2 Mar 2021 22:45:12 +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=87=D0=B5=D1=82=D0=B2?= =?UTF-8?q?=D1=91=D1=80=D1=82=D0=BE=D0=B9=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=20=D1=81=D0=B2=D1=8F=D0=B7=D0=BD=D1=8B?= =?UTF-8?q?=D0=BC=20=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/Makefile | 24 +++++++++++ list/list.h | 100 ++++++++++++++++++++++++++++++++++++++++++++++ list/task4.cpp | 42 +++++++++++++++++++ list/zadachilist.pdf | Bin 0 -> 43739 bytes structures/teorylist3.pdf | Bin 192869 -> 0 bytes theory/teorylist3.pdf | Bin 0 -> 192869 bytes 6 files changed, 166 insertions(+) create mode 100644 list/Makefile create mode 100644 list/list.h create mode 100644 list/task4.cpp create mode 100644 list/zadachilist.pdf delete mode 100644 structures/teorylist3.pdf create mode 100644 theory/teorylist3.pdf diff --git a/list/Makefile b/list/Makefile new file mode 100644 index 0000000..4a9376f --- /dev/null +++ b/list/Makefile @@ -0,0 +1,24 @@ +CXX=g++ +CFLAGS=-g -Wall +COMPILE=$(CXX) $(CFLAGS) + +task4: + $(COMPILE) -o task.out task4.cpp +test4: task4 + @printf "9\n5 2 9 1 3 7 9 2 9" | ./task.out + @printf "Answer: 5 9 1 3 7 9 9\n" + +task7: + $(COMPILE) -o task.out task7.cpp +test7: task7 + @printf "9\n6\n5 2 9 1 3 7 9 2 9" | ./task.out + @printf "Answer: 5 2 1 3 2 9 7 9 9\n" + +task15: + $(COMPILE) -o task.out task15.cpp +test15: task15 + @printf "9\n3\n1 2 3 4 5 6 7 8 9" | ./task.out + @printf "Answer: 1\n" + +clean: + rm task.out diff --git a/list/list.h b/list/list.h new file mode 100644 index 0000000..fe2c967 --- /dev/null +++ b/list/list.h @@ -0,0 +1,100 @@ +#include + +struct list +{ + int inf; + list *next; + list *prev; +}; + + +void push(list *&h, list *&t, int x) +{ + list *r = new list; + r->inf = x; + r->next = NULL; + if (!h && !t) + { + r->prev = NULL; + h = r; + } + else + { + t->next = r; + r->prev = t; + } + t = r; +} + +void print(list *h, list *t) +{ + list *p = h; + while (p) + { + std::cout << p->inf << " "; + p = p->next; + } +} + +list *find(list *h, list *t, int x) +{ + list *p = h; + while (p) + { + if (p->inf == x) break; + p = p->next; + } + return p; +} + +void insert_after(list *&h, list *&t, list *r, int y) +{ + list *p = new list; + p->inf = y; + if (r == t) + { + p->next = NULL; + p->prev = r; + r->next = p; + t = p; + } + else { + r->next->prev = p; + p->next = r->next; + p->prev = r; + r->next = p; + } +} + +void del_node(list *&h, list *&t, list *r) +{ + if (r == h && r == t) + h = t = NULL; + else if (r == h) + { + h = h->next; + h->prev = NULL; + } + else if (r == t) + { + t = t->prev; + t->next = NULL; + } + else + { + r->next->prev = r->prev; + r->prev->next = r->next; + } + delete r; +} + +void del_list(list *&h, list *&t) +{ + while (h) + { + list *p = h; + h = h->next; + h->prev = NULL; + delete p; + } +} diff --git a/list/task4.cpp b/list/task4.cpp new file mode 100644 index 0000000..c217664 --- /dev/null +++ b/list/task4.cpp @@ -0,0 +1,42 @@ +#include +#include "list.h" + +using namespace std; + +void solve(list *&h, list *&t) +{ + list *cur = h; + while (cur) + { + if (cur->inf % 2 == 0) + { + list *tmp = cur; + cur = cur->next; + del_node(h, t, tmp); + } + else cur = cur->next; + } +} + +int main() +{ + int n; + cout << "n = "; + cin >> n; + + list *head = NULL; + list *tail = NULL; + int x; + for (int i = 0; i < n; i++) + { + cin >> x; + push(head, tail, x); + } + + solve(head, tail); + print(head, tail); + cout << endl; + + return 0; + +} diff --git a/list/zadachilist.pdf b/list/zadachilist.pdf new file mode 100644 index 0000000..5f6f037 Binary files /dev/null and b/list/zadachilist.pdf differ diff --git a/structures/teorylist3.pdf b/structures/teorylist3.pdf deleted file mode 100644 index 7cc2f16..0000000 Binary files a/structures/teorylist3.pdf and /dev/null differ diff --git a/theory/teorylist3.pdf b/theory/teorylist3.pdf new file mode 100644 index 0000000..7cc2f16 Binary files /dev/null and b/theory/teorylist3.pdf differ -- cgit v1.2.3