Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Задание 6, Смольянинова У-195 😋
- #include <iostream>
- #include <queue>
- #include <string>
- using namespace std;
- //звонок
- struct Zvonok {
- int nomer; //кто звонил
- int time; //время в минутах
- Zvonok* next; //следующий звонок в списке
- Zvonok(int n, int t)
- {
- nomer = n;
- time = t;
- next = nullptr;
- }
- };
- //звонки абонента
- struct Zvonki {
- Zvonok* begin; //начало списка
- Zvonok* end; //конец списка
- void print()
- {
- Zvonok* temp = begin;
- while (temp)
- {
- cout << "Номер " << temp->nomer << " ; " << temp->time << "минут ; " << temp->time * 5 << "руб. стоил разговор " << endl;
- temp = temp->next;
- }
- delete temp;
- }
- };
- //абонент
- struct Abonent {
- int nomer; //номер
- string fio;
- Zvonki* zvonki;
- Abonent* next; //следующий абонент в списке
- Abonent(int n, string f) {
- nomer = n; fio = f; next = nullptr;
- zvonki = new Zvonki;
- zvonki->begin = nullptr;
- zvonki->end = nullptr;
- }
- };
- //список абонентов
- struct Abonenti {
- Abonent* begin; //начало списка
- Abonent* end; //конец списка
- void print()
- {
- Abonent* temp = begin;
- while (temp)
- {
- cout << "Номер " << temp->nomer << " ; ФИО " << temp->fio << endl;
- if (temp->zvonki)
- {
- cout << "Список звонков " << temp->nomer << endl;
- temp->zvonki->print();
- }
- temp = temp->next;
- }
- delete temp;
- }
- Abonent* poisk(int num)
- {
- Abonent* temp = begin;
- while (temp)
- {
- if (temp->nomer == num)
- return temp;
- temp = temp->next;
- }
- delete temp;
- }
- };
- void sortASC(Abonenti* list)
- {
- Abonent* begin = list->begin;
- Abonent* end = list->end;
- Abonent* root = begin;
- Abonent* new_root = nullptr;
- while (root)
- {
- Abonent* node = root;
- root = root->next;
- if (!new_root || node->nomer < new_root->nomer)
- {
- node->next = new_root;
- new_root = node;
- }
- else
- {
- Abonent* current = new_root;
- while (current->next && !(node->nomer < current->next->nomer))
- {
- current = current->next;
- }
- node->next = current->next;
- current->next = node;
- }
- }
- delete root;
- begin = new_root;
- }
- //добавить абонента в список
- void addAbonent(Abonent* temp, Abonenti* list)
- {
- if (!list->begin)
- {
- list->begin = temp;
- list->end = temp;
- return;
- }
- if (list->begin == list->end)
- {
- list->end = temp;
- list->begin->next = list->end;
- return;
- }
- list->end->next = temp;
- list->end = temp;
- }
- //добавить звонок в список
- void addZvonok(Zvonok* temp, Zvonki* list)
- {
- if (!list->begin)
- {
- list->begin = temp;
- list->end = temp;
- return;
- }
- if (list->begin == list->end)
- {
- list->end = temp;
- list->begin->next = list->end;
- return;
- }
- list->end->next = temp;
- list->end = temp;
- }
- int main()
- {
- setlocale(0, "rus");
- Abonent* a1 = new Abonent(7582, "Говфывфыв");
- Abonent* a2 = new Abonent(3421, "Говфывфыв");
- Abonent* a3 = new Abonent(8999, "Говфывфыв");
- Abonenti* list = new Abonenti;
- list->begin = nullptr;
- list->end = nullptr;
- addAbonent(a1, list);
- addAbonent(a2, list);
- addAbonent(a3, list);
- cout << "1: сортировать" << endl;
- cout << "2: вывести список со всеми разговорами" << endl;
- cout << "3: ввести номер и врея разговора" << endl;
- Abonent* result;
- Zvonok* temp;
- while (true)
- {
- int input;
- cin >> input;
- switch (input)
- {
- case 1:
- sortASC(list);
- break;
- case 2:
- list->print();
- break;
- case 3:
- cout << "введите номер и время" << endl;
- int num; int t;
- cin >> num >> t;
- temp = new Zvonok(num, t);
- result = list->poisk(num);
- if (result)
- addZvonok(temp, result->zvonki);
- break;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment