Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include "iostream"
- #include "iostream"
- using namespace std;
- struct spisok {
- int info;
- spisok *next, *prev;
- } *beginn, *en;
- void add()
- {
- int in, menu1;
- spisok *t = new spisok;
- cout << "element: ";
- cin >> in;
- t->info = in;
- if (beginn == NULL)
- {
- beginn = en = t;
- t->next = t->prev = NULL;
- }
- else
- {
- while (true)
- {
- cout << "1.v nachalo ocheredi \n2.v konec ocheredi\n";
- cin >> menu1;
- switch (menu1)
- {
- case 1:
- t->prev = NULL;
- t->next = beginn;
- beginn->prev = t;
- beginn = t;
- return;
- case 2:
- t->next = NULL;
- t->prev = en;
- en->next = t;
- en = t;
- return;
- }
- }
- }
- }
- void viev()
- {
- if (beginn == NULL)
- cout << "-\n\n";
- else
- {
- spisok *f;
- int menu2;
- while (true)
- {
- cout << "1.s nachala \n2.s konca \n";
- cin >> menu2;
- switch (menu2)
- {
- case 1:
- f = beginn;
- while (f)
- {
- cout << f->info << " ";
- f = f->next;
- }
- cout << endl;
- return;
- case 2:
- f = en;
- while (f)
- {
- cout << f->info << " ";
- f = f->prev;
- }
- cout << endl;
- return;
- }
- }
- }
- }
- void dlia_udalic()
- {
- if (beginn == NULL)
- cout << "-\n\n";
- else
- {
- spisok *f;
- int menu2;
- while (true)
- {
- cin >> menu2;
- switch (menu2)
- {
- case 1:
- f = beginn;
- while (f)
- {
- cout << f->info << " ";
- f = f->next;
- }
- cout << endl;
- return;
- case 2:
- f = en;
- while (f)
- {
- cout << f->info << " ";
- f = f->prev;
- }
- cout << endl;
- return;
- }
- }
- }
- }
- void udalic()
- {
- while (beginn)
- {
- spisok *t = beginn;
- beginn = beginn->next;
- delete t;
- }
- }
- void udalic_ne_vsio()
- {
- spisok *f = beginn;
- while (f)
- {
- if (f->info % 2 == 0)
- {
- if (f == beginn)
- {
- spisok *q = beginn;
- beginn = beginn->next;
- beginn->prev = NULL;
- f = f->next;
- delete q;
- }
- else if (f == en)
- {
- spisok *q = en;
- en = en->prev;
- en->next = NULL;
- f = f->next;
- delete q;
- }
- else
- {
- spisok *q = f;
- (f->prev)->next = f->next;
- (f->next)->prev = f->prev;
- f = f->next;
- delete q;
- }
- }
- else f = f->next;
- }
- }
- void main()
- {
- setlocale(LC_CTYPE, "russian");
- int menu;
- while (true)
- {
- cout << "chto sdelac: \n1.dobaavic \n2.prosmotr \n3.udalic \n4.udalic vse \n0.zalric \n";
- cin >> menu;
- switch (menu)
- {
- case 1: add(); break;
- case 2: viev(); break;
- case 3: udalic_ne_vsio(); dlia_udalic(); break;
- case 4: udalic(); break;
- case 0: return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement