Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Queue
- {
- float info;
- Queue* next;
- };
- float Print(Queue*& head) {
- Queue* tmp = head;
- return head->info;
- }
- void Push(Queue*& head, Queue*& last, float info)
- {
- Queue* newElem = new Queue;
- newElem->info = info;
- newElem->next = NULL;
- if (head != NULL)
- last = last->next = newElem;
- else
- head = last = newElem;
- }
- void Empty(int sz)
- {
- if (sz==0) cout << "Очередь пуста";
- else
- cout << "Очередь не пуста";
- }
- void Full(int sz)
- {
- if (sz == 7) cout << "Очередь полна, заполнение невозможно";
- else
- cout << "Очередь не полна";
- }
- float Pop(Queue*& head, Queue*& last)
- {
- Queue* tmp = head;
- head = head->next;
- float result = tmp->info;
- delete tmp;
- if (head == NULL)
- last = NULL;
- return result;
- }
- int main()
- {
- Queue* qHead = NULL, * qLast = NULL;
- string command;
- float number;
- setlocale(LC_ALL, "rus");
- int size=0;
- cout << "Введите команды управления очередью:\nPUSH - добавление элементa\nPOP - удаление элемента из очереди и его вывод\nPRINT - вывод первого в очереди\nEMPTY - проверка пустоты очереди\nFULL - проверка полноты очереди\nEND - вывод элементов очереди\n\n";
- while (true)
- {
- cin >> command;
- if (command == "END")
- break;
- else if (command == "PUSH")
- {
- if (size < 7) {
- size++;
- cin >> number;
- Push(qHead, qLast, number);
- }
- else
- Full(size);
- }
- else if (command == "POP")
- {
- if (size > 0) {
- size--;
- cout << Pop(qHead, qLast) << endl;
- }
- else
- Empty(size);
- }
- else if (command == "PRINT")
- cout << Print(qHead) << endl;
- else if (command == "FULL")
- Full(size);
- else if (command == "EMPTY")
- Empty(size);
- else
- cout << "Такой команды нет!\n";
- };
- cout << "В очереди осталось: ";
- while (qHead != NULL)
- cout << Pop(qHead, qLast) << ' ';
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement