Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "windows.h"
- #include <fstream>
- using namespace std;
- struct list
- {
- int info;
- list* next, *prev;
- };
- void Create(list*& head, list*& end);
- void Add(list*& head, list*& end);
- void Add_end(list*& end, int inf);
- void Add_head(list*& head, int inf);
- void Del_el(list*& head, int inf);
- void Delete(list*& head);
- void View(list*& head, list*& end);
- void View_head(list*& head);
- void View_end(list*& end);
- int main()
- {
- setlocale(LC_ALL, "rus");
- list* head = nullptr;
- list* end = nullptr;
- int choice,info=0;
- while (true)
- {
- cout << " 1. Создание\n 2. Добавление\n 3. Удаление\n 4. Просмотр \n 5. Сортировка\n 6. Выход" << endl;
- cin >> choice;
- switch (choice)
- {
- case 1:
- Create(head, end);
- break;
- case 2:
- Add(head, end);
- break;
- case 3:
- Del_el(head,info);
- break;
- case 4:
- View(head,end);
- break;
- case 5:
- //Solution(head, end);
- break;
- case 6:
- exit(0);
- break;
- default:
- cout << "Повторите еще раз" << endl;
- break;
- }
- }
- }
- void Create(list*& head, list*& end)
- {
- if (head == NULL)
- {
- int kolvo, i, info;
- cout << "Введите количество элементов" << endl;
- cin >> kolvo;
- if (cin.fail() || kolvo < 0)
- {
- cout << "Условия ввода не соблюдены" << endl;
- return;
- }
- cout << "1-ый " ;
- cin >> info;
- list* t = new list;
- t->info = info;
- t->next = head;
- t->prev = end;
- head = end = t;
- for (i = 1; i < kolvo; i++)
- {
- cout << i + 1 << "-ый ";
- cin >> info;
- Add_end(head, info);
- }
- }
- else
- cout << "Список уже создан" << endl;
- }
- void Add(list*& head, list*& end)
- {
- cout << " 1.Добавить элемент в начало списка\n 2.Добавить элемент в конец списка" << endl;
- int u,element;
- cin >> u;
- switch (u)
- {
- case 1:
- cout << "Введите добавляемый элемент" << endl;
- cin >> element;
- Add_head(head, element);
- break;
- case 2:
- cout << "Введите добавляемый элемент" << endl;
- cin >> element;
- Add_end(end, element);
- break;
- default:
- cout << "Данный символ ввести невозможно" << endl;
- break;
- }
- }
- void Add_end(list*& end, int inf)
- {
- list* t = new list;
- t->info = inf;
- t->next = NULL;
- t->prev = end;
- end->next = t;
- end = t;
- }
- void Add_head(list*&head,int inf)
- {
- list* t = new list;
- t->prev = NULL;
- t->info = inf;
- t->next = head;
- head->prev = t;
- head = t;
- }
- void Del_el(list*& head, int inf)
- {
- if (head != NULL)
- {
- list* t = nullptr;
- t = head;
- cout << inf;
- head = head->next;
- delete t;
- }
- }
- void Delete(list*& head)
- {
- list* t = nullptr;
- while (head!= NULL)
- {
- t =head;
- head = head->next;
- delete t;
- }
- }
- void View(list*& head, list*& end)
- {
- if (head == NULL)
- {
- cout << "Список пуст!" << endl;
- return;
- }
- cout << "\n 1. Просмотр списка сначала\n 2. Просмотр списка с конца" << endl;
- int r;
- cin >> r;
- switch (r)
- {
- case 1:
- View_head(head);
- break;
- case 2:
- View_end(end);
- break;
- default:
- cout << "Значение введено неправильно" << endl;
- return;
- }
- }
- void View_head(list*& head)
- {
- list* t =head;
- while (t != NULL)
- {
- cout << "Элемент равен " << t->info << endl;
- t = t->next;
- }
- }
- void View_end(list*& end)
- {
- list* t =end;
- while (t != NULL)
- {
- cout << "Элемент равен " << t->info << endl;
- t = t->prev;
- }
- }
- //void Solution(list*& head, list*& end)
- //{
- //
- //}
Add Comment
Please, Sign In to add comment