Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Queues

Washington State University

CptS 122
• A queue is referred to as a first-in, first-out (FIFO)
data structure
• A queue is also considered a restricted or
constrained list

Queues
Queue Operations

enqueue - new item is added to the queue

dequeue - front node is removed from the


queue
isEmpty - is the Queue empty
Queue Functions

• Constructor • isEmpty()

• Destructor • clear()
• enqueue()

• dequeue()
Queue Class Implementation

Queue.h Queue.cpp main.cpp


Queue Applications

PRINTERS QUEUE SIMULATIONS OF


PRINT REQUESTS; REAL WORLD
PROCESSES, SUCH
FIRST-COME,
AS MOVIE LINES,
FIRST-SERVE GROCERY STORE
LINES, ETC.
ADTs

• You can implement a queue without using links;

• Hence, you can use an array as the underlying structure for the queue

• A queue is essentially a restricted linked list, where one additional pointer is needed to
keep track of the back, tail, or rear of the queue
Write a program that opens two text files
and reads their contents into two
separate queues. The program should
then determine whether the files are
identical by comparing the characters in
Example Problem: the queues. When two nonidentical
characters are encountered, the program
files_queuesMain.cpp should display a message indicating that
the files are not the same. If both queues
contain the same set of characters, a
message should be displayed indicating
that the files are identical.

You might also like