Created
May 14, 2022 11:34
-
-
Save bhavjot/79ed9be10b0e8fc0bbb6c70146ad8b94 to your computer and use it in GitHub Desktop.
This file contains 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
class StackQueue{ | |
Stack<int> st1 = new Stack<int>(); | |
Stack<int> st2 = new Stack<int>(); | |
//Complete the functions | |
public void Push(int x){ | |
while(st2.Count>0){ | |
st1.Push(st2.Pop()); | |
} | |
st1.Push(x); | |
return; | |
} | |
public int Pop(){ | |
while(st1.Count>0){ | |
st2.Push(st1.Pop()); | |
} | |
return st2.Count>0?st2.Pop(): -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment