0

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>
skaffman
  • 398,947
  • 96
  • 818
  • 769
ISJ
  • 509
  • 2
  • 8
  • 17

2 Answers2

3

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;

}
Mark Pope
  • 11,244
  • 10
  • 49
  • 59
2

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;

}
corsiKa
  • 81,495
  • 25
  • 153
  • 204