This code implement the Deque data structure using array. Java programming language.
Problem statement:
Implement the Deque abstract data type using an array, called ArrayDeque. Implement the data structure yourself, do not use extra Java Collection classes.
For efficiency first, last, enqueueRear, enqueueFront, dequeueRear, dequeueFront, clear, size, and isEmpty should all be O(1) operations. Feel free to add any necessary private helper methods and a suitable toString which returns a string representation for your deque implementation.
Further enhance these classes to make sure all methods are safe from unexpected events using appropriate exception handling (example, if user code tries to remove something from the deque when empty, it should throw an appropriate exception). Create a test class with a suitable main method which effectively tests all operations on one or both Deque implementations.