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
  • 390,936
  • 96
  • 800
  • 764
ISJ
  • 501
  • 2
  • 8
  • 16

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
  • 10,994
  • 10
  • 47
  • 58
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
  • 79,375
  • 23
  • 153
  • 199