Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node {
- node* next;
- int info;
- };
- void push(node*& Begin, node*& End) {
- node* el = new node;
- cout << "Значение: ";
- cin >> el->info;
- el->next = NULL;
- if (End == nullptr) {
- Begin = End = el;
- }
- else {
- End = el;
- }
- }
- bool isEmpty(node* Begin) {
- if (Begin == nullptr)
- cout << "Очередь пуста\n";
- return Begin == nullptr;
- }
- void queueList(node* Begin) {
- if (isEmpty(Begin))
- return;
- node* temp = Begin;
- while (temp != nullptr) {
- cout << temp->info << " ";
- temp = temp->next;
- }
- }
- void pop(node*& Begin) {
- if (isEmpty(Begin))
- return;
- node* temp = Begin;
- temp = Begin;
- Begin = Begin->next;
- delete temp;
- }
- int peek(node* Begin) {
- if (isEmpty(Begin))
- return -1;
- return Begin->info;
- }
- int main() {
- setlocale(LC_ALL, "Rus");
- node* Begin = nullptr, * End = nullptr;
- push(Begin, End);
- push(Begin, End);
- push(Begin, End);
- queueList(Begin);
- pop(Begin);
- cout << endl;
- queueList(Begin);
- cout << endl;
- int num = peek(Begin);
- cout << num;
- }
Advertisement
Add Comment
Please, Sign In to add comment