Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <forward_list>
- #include <vector>
- using namespace std;
- bool clear(stack<int>& cstk);
- void print(stack<int> pstk);
- void isEmpty(stack<int>& estk);
- bool paste(stack<int>& instk);
- void extract(stack<int>& fromstk, int& el);
- int main()
- {
- setlocale(LC_ALL, "rus");
- forward_list<int> stklist;
- stack<int> stk;
- int pos;
- const int size = 5;
- cout << "Ввод стека:\n";
- for (int i = 0; i < size; i++)
- {
- int el;
- cin >> el;
- stk.push(el);
- }
- stack<int> stk2 = stk;
- print(stk);
- vector<int> vec;
- for (int i = 0; i < size; i++)
- {
- if (i == 0)
- pos = i;
- vec.push_back(stk.top());
- stk.pop();
- }
- cout << "\nа) ";
- for (int i : vec)
- cout << i << " ";
- cout << "\nИндекс компоненты массива, занятой последним элементом стека = " << pos;
- for (int i = stk2.size(); i > 0; i--)
- {
- int temp = stk2.top();
- stk2.pop();
- stklist.push_front(temp);
- }
- cout << "\nб) ";
- for (int i : stklist)
- cout << i << " ";
- }
- bool clear(stack<int>& cstk)
- {
- if (cstk.empty())
- return true;
- while (!cstk.empty())
- {
- cstk.top();
- cstk.pop();
- }
- return true;
- }
- void print(stack<int> pstk)
- {
- while (!pstk.empty())
- {
- int el = pstk.top();
- pstk.pop();
- cout << el << " ";
- }
- }
- void isEmpty(stack<int>& estk)
- {
- if (estk.empty())
- cout << "\nСтэк пустой";
- else cout << "\nСтэк не пустой";
- }
- bool paste(stack<int>& instk)
- {
- cout << "\nЭлемент для вставки: ";
- int el;
- cin >> el;
- instk.push(el);
- return true;
- }
- void extract(stack<int>& fromstk, int& el)
- {
- el = fromstk.top();
- fromstk.pop();
- }
Advertisement
Add Comment
Please, Sign In to add comment