Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stack{
- long long S = [1000001];
- int ptr;
- public:
- Stack(){
- ptr = 0;
- }
- void push(long long value){
- if (!ptr)
- S[++ptr] = value;
- else S[++ptr] = min(S[ptr], value);
- ptr++;
- }
- void pop(){
- if (ptr) ptr--;
- }
- int size(){
- return ptr;
- }
- long long min_Element(){
- return S[ptr];
- }
- bool empty(){
- if(!ptr) return 1;
- return 0;
- }
- };
- class Queue{
- Stack S1, S2;
- int ptr1, ptr2;
- public:
- Queue(){
- ptr1 = 0;
- ptr2 = 0;
- }
- void push(long long value){
- S1.push(value);
- }
- void pop(){
- if (ptr1){
- while (!S1.empty()){
- S2.push(S1.min_Element());
- }
- S2.pop();
- }
- int size(){
- return ptr1;
- }
- bool empty(){
- if (!ptr1 && !ptr2) return 1;
- return 0;
- }
- long long min_Element(){
- if(!S1.empty() || !S2.empty()){
- if(S1.empty() || S2.empty()){
- return (S1.empty()? S2.min_Element():S1.min_Element());
- }
- else return min(S1.min_Element(), S2.min_Element());
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement