Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- //W stosie wszystkie dane dodajemy na początku strukturo LIFO - Last In, First Out
- struct stack {
- int value;
- stack *last;
- };
- void push(stack*& head, int value)
- {
- stack *temp = new stack;
- temp->value = value;
- temp->last = head;
- head = temp;
- }
- void show_stack(stack* head)
- {
- stack* temp = head;
- while (temp != NULL)
- {
- std::cout << temp->value << " ";
- temp = temp->last;
- }
- }
- void pop_first(stack*& head)
- {
- stack* temp = head;
- head = head->last;
- delete temp;
- }
- void stos()
- {
- stack* stos = nullptr;
- push(stos, 1);
- push(stos, 2);
- push(stos, 3);
- push(stos, 4);
- show_stack(stos);
- pop_first(stos);
- std::cout << "\n";
- show_stack(stos);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement