Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int maxn = 1000;
- struct stek {
- int niza[maxn];
- int idx;
- void init() {
- idx = -1;
- }
- void push(int x) {
- if(idx + 1 >= maxn) {
- cout << "NEMA DOVOLNO KAPACITET" << endl;
- return;
- }
- idx++;
- niza[idx] = x;
- }
- int pop() {
- if(idx == -1) {
- cout << "NEMA NITU EDEN ELEMENT VO STEKOT" << endl;
- return -1;
- }
- int result = niza[idx];
- idx--;
- return result;
- }
- int top() {
- if(idx == -1) {
- cout << "NEMA NITU EDEN ELEMENT VO STEKOT" << endl;
- return -1;
- }
- return niza[idx];
- }
- int size() {
- return idx + 1;
- }
- int isEmpty() {
- if(idx == -1) {
- return 1;
- }
- else {
- return 0;
- }
- }
- };
- int main() {
- int n;
- cin >> n;
- stek A;
- A.init();
- stek B;
- B.init();
- for(int i = 0; i < n; i++) {
- int pacient;
- cin >> pacient;
- if(pacient == 2) {
- A.push(2);
- }
- else {
- B.push(pacient);
- }
- }
- cout << "B: ";
- while(B.isEmpty() == 0) {
- int x = B.pop();
- if(x == 1) {
- A.push(x);
- }
- else {
- cout << x << " ";
- }
- }
- cout << endl;
- cout << "A: " << endl;
- while(A.isEmpty() == 0) {
- int x = A.pop();
- cout << x << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement