Welcome to an exciting exploration of two fundamental data structures: Stacks and Queues! Remember, data structures store and organize data in a manner that is structured and efficient. Stacks and Queues are akin to stacking plates and standing in a line, respectively. Intriguing, isn't it? Let's dive in!
ArrayDeque
(Double-Ended Queue) is a versatile data structure that combines the features of both Stack and Queue. It provides efficient methods for adding and removing elements from both ends of the collection:
- Stack Operations:
addLast()
: Adds an element to the end (top of stack)removeLast()
: Removes and returns the last element (top of stack)
- Queue Operations:
addLast()
: Adds an element to the end of queueremoveFirst()
: Removes and returns the first element
Additional useful methods include:
isEmpty()
: Checks if the collection is emptysize
: Returns the number of elements- : Views the first element without removing it
