The most sophisticated of the stack data structures is the deque or double ended queue.
To see how this works imagine a deck of cards which is where the name of the data structure comes from. You can take a card from the top or bottom of the deck and you can add a card to the top or bottom of a deck.
In other words a deque really is a double ended queue in that you can join or leave the queue at the front or the back.
Once again the Array object has an additional method that you can use to implement a deque. The shift method completes the set of "queing" mutator methods and it removes and element from the front or start of the Array.
So we now have
pop and push - remove or add to the end of the Array
shift and unshift - remove or add to the start of the Array.
There are no real standard labels for manipulating a deque. The method names used in this example are closest to C++ which used push_back, push_front etc. for a deque. To use it you simply call the methods you need according to where you want to add or remove items.
For example, what does the following code display:
Deques aren't as common in simple algorithms and so you might never need to use on.
They can be useful however in job scheduling algorithms where there are multiple jobs and agents. Each agent takes tasks from the front of their deque of tasks but if an agent has nothing to do they take tasks from the end of the deque belonging to another agent.
The jQuery approach to Ajax is built on the jqXHR object which wraps the XmlHttpRequest object that the browser provides. It isn't often that you need delve this deeply into jQuery Ajax, but when you [ ... ]