Interview Questions

Implement Queue using Stack. Help to get a code with resolving complexity.

Microsoft Interview Questions and Answers


(Continued from previous question...)

128. Implement Queue using Stack. Help to get a code with resolving complexity.

Question:
Implement Queue using Stack. Help to get a code with resolving complexity.


maybe an answer:


public class QeueUsingTwoStacks
{
Stack pushStack = new Stack();
Stack popStack = new Stack();
public void Enqueue(int data)
{
Console.WriteLine("Enqueued:{0}", data);
pushStack.Push(data);
}
public SinglyNode Dequeue()
{
if (popStack.isEmpty())
{
while (!pushStack.isEmpty())
popStack.Push(pushStack.Pop().data);
}
return popStack.Pop();
}
}

(Continued on next question...)

Other Interview Questions