This commit is contained in:
Electrominch
2022-10-11 01:45:16 +03:00
parent c019e8856c
commit 02afed9c4c
34 changed files with 691 additions and 3 deletions

View File

@@ -0,0 +1,35 @@
namespace _232._Implement_Queue_using_Stacks;
public class MyQueue
{
private Stack<int> _sInput = new Stack<int>();
private Stack<int> _sOutput = new Stack<int>();
public void Push(int x)
{
while(_sOutput.TryPop(out int res))
_sInput.Push(res);
_sInput.Push(x);
}
public int Pop()
{
while(_sInput.TryPop(out int res))
_sOutput.Push(res);
return _sOutput.Pop();
}
public int Peek()
{
while (_sInput.TryPop(out int res))
_sOutput.Push(res);
return _sOutput.Peek();
}
public bool Empty()
{
while (_sInput.TryPop(out int res))
_sOutput.Push(res);
return _sOutput.Count == 0;
}
}