Skip to content

Instantly share code, notes, and snippets.

@bhavjot
Created May 14, 2022 11:34
Show Gist options
  • Save bhavjot/79ed9be10b0e8fc0bbb6c70146ad8b94 to your computer and use it in GitHub Desktop.
Save bhavjot/79ed9be10b0e8fc0bbb6c70146ad8b94 to your computer and use it in GitHub Desktop.
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