Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Queue
- {
- int info;
- Queue *next;
- };
- void Push(Queue *&first, Queue *&last, int info)
- {
- Queue *newElem = new Queue;
- newElem->info = info;
- newElem->next = NULL;
- if (first != NULL)
- last = last->next = newElem;
- else
- first = last = newElem;
- }
- int Pop(Queue *&first, Queue *&last)
- {
- Queue *tmp = first;
- first = first->next;
- int result = tmp->info;
- delete tmp;
- if (first == NULL)
- last = NULL;
- return result;
- }
- int main()
- {
- Queue *qFirst = NULL, *qLast = NULL;
- string command;
- int number;
- setlocale(LC_ALL, "rus");
- cout << "Вводите команды управления очередью (признак окончания ввода - END):\n";
- while (true)
- {
- cin >> command;
- if (command == "END")
- break;
- else if (command == "PUSH")
- {
- cin >> number;
- Push(qFirst, qLast, number);
- }
- else if (command == "POP")
- Pop(qFirst, qLast);
- else
- cout << "Такой команды нет!\n";
- };
- cout << "В очереди осталось: ";
- while (qFirst != NULL)
- cout << Pop(qFirst, qLast) << ' ';
- cout << endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment