Created
October 13, 2019 07:46
-
-
Save surinoel/d24c7a1f716f71655017c9f0df6cb191 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#define SIZE 1000 | |
int stack1[SIZE], stack2[SIZE]; | |
int top1 = -1, top2 = -1; | |
void push(int data) { | |
if (top1 >= SIZE - 1) return; | |
stack1[++top1] = data; | |
} | |
int pop() { | |
if (top2 == -1 && top1 != -1) { | |
for (int i = top1; i >= 0; i--) { | |
stack2[++top2] = stack1[i]; | |
} | |
} | |
return stack2[top2--]; | |
} | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
for (int i = 0; i < n; i++) { | |
int x; | |
cin >> x; | |
push(x); | |
} | |
for (int i = 0; i < n; i++) { | |
cout << pop() << ' '; | |
} | |
cout << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment