In: Computer Science
Two direct applications of stacks:
* Stacks are commonly used in the history of all the website
webpages-visited in a web browser.
* Another user application level use case is when users use the
'undo' command or feature in any text editor to undo any mistakes
or recent actions or unintended incorrect characters typed in
following the undo sequence in order.
Two indirect applications of stacks:
* Stacks are used as a very common data structure in
programs.
* Stacks are used as a component of other data structures.
* It is also used as an auxiliary data structure for
algorithms.
An example from the daily life of queues:
* Car owners waiting in their respective cars for their turn to
fill gas into their car gas tanks at gas stations.
* Customers waiting in lines for different services where they
follow the first-come and first-serve policy or rule.
* In computer technology, different computers wait for shared
resources such as printers, etc.
What the main queue operations and do they
do:
* Insertions and deletions happen in the first-in and first-out
scheme/fashion or on first-come and first-serve basis.
* Queues store arbitrary items, objects, values, or data.
* Insertions happen at the rear end of the queue whereas the
deletions/removals happen at the front end of the queue.
* To insert an object at the rear end of the queue it uses the
function enqueue (object) where object value is provided as input
to be inserted.
*To remove/delete an object from the queue at the front end of the
queue and return it as an output (with its value), it uses the
function dequeue() returning with the object value
been removed.
* Queues also have auxiliary queue operations such as to display or
return the object at the front end of the queue without deleting or
removing it with the function front().
* To return or display the value with the number of objects stored
in a queue using the operation size(), this
basically gives the queue size in integer data type.
* Another operation is performed to indicate if the queue is empty
or not letting know if the queue has at least one object stored in
it or nil. It uses the function isEmpty() which
returns the value in boolean data type.
There is an exception operation which the queue performs when an attempt is made to execute the dequeue operation at the front end of the queue to delete/remove the object and return the same when there is no object in the queue (not even a single object) or the queue is empty and it throws an error message EmptyQueueException.