Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Double-Ended Queues

Rating
-
Sold
-
Pages
3
Uploaded on
18-02-2023
Written in
2022/2023

This is material in the Data Structure course of the Department of Mathematics, Faculty of Science and Technology UIN Sunan Gunung Djati Bandung with lecturer Dian Nuraiman, P. hD

Institution
Course

Content preview

6.3. Double-Ended Queues 247

6.3 Double-Ended Queues
We next consider a queue-like data structure that supports insertion and deletion
at both the front and the back of the queue. Such a structure is called a double-
ended queue, or deque, which is usually pronounced “deck” to avoid confusion
with the dequeue method of the regular queue ADT, which is pronounced like the
abbreviation “D.Q.”
The deque abstract data type is more general than both the stack and the queue
ADTs. The extra generality can be useful in some applications. For example, we
described a restaurant using a queue to maintain a waitlist. Occassionally, the first
person might be removed from the queue only to find that a table was not available;
typically, the restaurant will re-insert the person at the first position in the queue. It
may also be that a customer at the end of the queue may grow impatient and leave
the restaurant. (We will need an even more general data structure if we want to
model customers leaving the queue from other positions.)



6.3.1 The Deque Abstract Data Type
To provide a symmetrical abstraction, the deque ADT is defined so that deque D
supports the following methods:

D.add first(e): Add element e to the front of deque D.
D.add last(e): Add element e to the back of deque D.
D.delete first( ): Remove and return the first element from deque D;
an error occurs if the deque is empty.
D.delete last( ): Remove and return the last element from deque D;
an error occurs if the deque is empty.

Additionally, the deque ADT will include the following accessors:

D.first( ): Return (but do not remove) the first element of deque D;
an error occurs if the deque is empty.
D.last( ): Return (but do not remove) the last element of deque D;
an error occurs if the deque is empty.
D.is empty( ): Return True if deque D does not contain any elements.
len(D): Return the number of elements in deque D; in Python,
we implement this with the special method len .

Written for

Institution
Course

Document information

Uploaded on
February 18, 2023
Number of pages
3
Written in
2022/2023
Type
Class notes
Professor(s)
Dian nuraiman, p. hd
Contains
All classes

Subjects

$10.75
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
alenamansika

Get to know the seller

Seller avatar
alenamansika Universitas Islam Negeri Sunan Gunung Djati Bandung
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions