Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- class FIFO {
- public:
- void push(int value) {
- main_stack.push(value);
- }
- int pop() {
- int result = 0;
- while (!main_stack.empty() && main_stack.size() > 1) {
- help_stack.push((int &&) main_stack.top());
- main_stack.pop();
- }
- result = main_stack.top();
- main_stack.pop();
- while (!help_stack.empty()) {
- main_stack.push((int &&) help_stack.top());
- help_stack.pop();
- }
- return result;
- }
- unsigned long size() {
- return this->main_stack.size();
- }
- private:
- stack<int> main_stack;
- stack<int> help_stack;
- };
- int main() {
- FIFO fifo;
- fifo.push(4);
- fifo.push(3);
- fifo.push(2);
- fifo.push(1);
- cout << fifo.pop(); // Powinno wypisać 4
- fifo.push(4);
- fifo.push(3);
- fifo.push(2);
- fifo.push(1);
- cout << fifo.pop(); // Powinno wypisać 3 jeszcze z poprzedniego dodania
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement