I want to look at double-ended queue implementation.
Any one who know the double-ended queue implementation can give the source code or the link.
I understand the double-ended queue. I just want to look at the source code. I want to to know how the complete double-ended queue is designed.
Thanks for any help.
the java.util.Queue may be too complicated for me. I just want to know some necessary member for Dequeue.
So I post my Dequeue.java source code .
Thanks for any suggestions for the below Dequeue.java code.
You ought to make the method names correspond to the names in the Deque interface. The names push and pop are usually applied to stacks, not queues, although you find the Deque interface can be used as a stack.
You have a class with instance fields in; you need to initialise that in the constructor. Then you can forget about the != null tests. If the array is null, then it is impossible for your class to perform any functionality at all. Your code to increase the size of the array is duplicated; it should be moved into a private method for resizing the capacity.
Your pop methods should throw an EmptyStackException when you have a size of 0, rather than returning -1. What happens if you push -1 onto your stack?
Your pop methods leave an unused reference on the stack. They should be implemented more like thisThis is more important with reference types; you need to set them to null, not 0, otherwise there is a risk of a memory leak.