DATA STRUCTURES AND ALGORITHMS
FILS, March 2014
Queue vs stack
instance of an abstract data type (ADT) that
formalizes the concept of restricted collection
(FIFO = first in first out)
QUEUES: BASIC OPERATIONS
Removes the element from the head of the queue and
Returns an error if the stack is empty
Adds the element x at the tail of the queue
Returns (but does not remove) the element at the head of
Returns 1 if the queue is empty and 0 otherwise
with a static data structure (array, circular
with a dynamic data structure (list)
Why do we use circular arrays instead of simple arrays?
QUEUES VS STACKS
Implement a stack using 2 queues. The corresponding class is
QueuedStack and has the following methods:
an empty constructor
There are several solutions for this task.
Using a similar approach, implement a queue using 2 stacks:
QUEUES AND STACKS: APPLICATIONS
Implement a stack which provides an efficient get minimum
function along with regular push and pop functionality.
Hint: use an auxiliary stack.
Taking into consideration that a queue can be implemented
using 2 stacks, use a similar approach for getting the
minimum element out of a queue.
Finish all the lab exercises.
Implement a messaging system using queues.
Messages are received in the order they are sent
You should use the following classes:
A Message object has a sender, recipient, content (make an array
of chars!!) and a date
A Message is placed in a queue by a MessageSender object
A Message is removed from a queue by a MessageReceiver object,
which can also display the content of the message.
Your queue class can receive any types of objects, including