0% found this document useful (0 votes)
79 views8 pages

L9 Queues PDF

A queue is a first-in, first-out (FIFO) data structure. It uses enqueue to add items to the back of the queue and dequeue to remove items from the front. Queues have common functions like isEmpty, clear, enqueue, and dequeue. They can be implemented with arrays or linked lists and have applications like print queues and simulation of real-world processes. The example problem reads two files into separate queues and compares the characters to determine if the files are identical.

Uploaded by

andrew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views8 pages

L9 Queues PDF

A queue is a first-in, first-out (FIFO) data structure. It uses enqueue to add items to the back of the queue and dequeue to remove items from the front. Queues have common functions like isEmpty, clear, enqueue, and dequeue. They can be implemented with arrays or linked lists and have applications like print queues and simulation of real-world processes. The example problem reads two files into separate queues and compares the characters to determine if the files are identical.

Uploaded by

andrew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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