hey, i have to create a TwoStacksQueue.java
that creates a queue using two stacks.
i just want to know how to implement Stack.java
into TwoStacksQueue.java
.
this is what i have:
public class TwoStacksQueue<Item> implements Stack<Item>
hey, i have to create a TwoStacksQueue.java
that creates a queue using two stacks.
i just want to know how to implement Stack.java
into TwoStacksQueue.java
.
this is what i have:
public class TwoStacksQueue<Item> implements Stack<Item>
If you are trying to implement a queue by using two stacks your class should be defined as a Queue. Then the internal representation is up to you. Maybe something like this:
public class TwoStacksQueue<Item> implements Queue<Item> {
private Stack stack1;
private Stack stack2;
}
I don't think you'd want to implements
a Stack. If you're going to use two stacks, you'll want something like this
public class TwoStacksQueue<E> {
Stack<E> firstStack;
Stack<E> secondStack;
}