LIFO method Stack types:
FixedStack, the BUFFER size is constant, if you add too many items it will throw aFullStackException. It's useful if you want to create a list of action without stressing the memory.GrowingStack, the BUFFER size is variable, if you add too many items it will double the size. It's useful if you don't care about the memory usage.CycleStack, the BUFFER size is constant, if you add too many items it will start erasing the older items. It is wrote with aO(1)complexity, so it is very efficient. Works better if you have to create an history.
Commands:
push(), add an elementsobjinside of the stack. parameters:Object objreturn:voidtop(), returns the last element inserted. parameters:Nonereturn:Object objpop(), return and remove the last element of the stack. parameters:Nonereturn:Object obj
FIFO method Queue types:
FixedQueue, the BUFFER size is constant, if you add too many items it will throw aFullQueueException. It is designed with anO(1), so the code is a bit complex.CycleQueue, the BUFFER size is constant, if you add too many items it will erase the older one and replace it with the newer one.GrowingQueue, the BUFFER size can increase if the queue is full. IfFullQueueExceptionis thrown, the BUFFER size doubles.
Commands:
enqueue(), add an elementsobjinside of the queue. parameters:Object objreturn:voidgetFront(), returns the first element inserted. parameters:Nonereturn:Object objdequeue(), return and remove the first element of the queue. parameters:Nonereturn:Object obj
Work with LIFO and FIFO methods, it's a Double Ended Queue.
Queue types:
FixedDeque, the BUFFER size is constant, if you add too many items it will throw aFullDequeException.CycleDequeTODOGrowingDeque, TODO
Commands:
enqueue(), add an elementsobjat the left side of the deque. parameters:Object objreturn:voidgetFront(), returns the element at the left end of the deque. parameters:Nonereturn:Object objdequeue(), return and remove the element at the left end of the deque. parameters:Nonereturn:Object objpush(), add an elementsobjat the right end of the deque. parameters:Object objreturn:voidtop(), returns the element at the right end of the deque. parameters:Nonereturn:Object objpop(), return and remove the last element at the right end of the deque. parameters:Nonereturn:Object obj
All ADT types share these methods:
isEmpty(), checks if the ADT is empty. parameters:Nonereturn:booleanMakeEmpty(), makes the ADT is empty (virtually). parameters:Nonereturn:Noneprint(), prints all the elements of the array. parameters:Nonereturn:String
You can change the BUFFER when you define the object, by default is set at 1024.
FixedStack myStack = new FixedStack(); //BUFFER = 1024
FixedStack myStack = new FixedStack(8); //BUFFER = 8
#Further implementations
Maps, trees, tables