1. Trang chủ
  2. » Mầm non - Tiểu học

Lecture Data structures and other objects using C++ - Chapter 8: Using a queue - Trường Đại học Công nghiệp Thực phẩm Tp. Hồ Chí Minh

7 9 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 7
Dung lượng 466,29 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The template  The template  parameter is the  parameter is the  type of the items  type of the items  that can be put in  that can be put in  the queue.. Array Implementation[r]

Trang 1

Chapter 8 introduces the  queue data type

Several example  applications of queues are  given in that chapter. 

This presentation describes  the queue operations and  two ways to implement a  queue

Data Structures

and Other Objects

Using C++

Trang 2

A queue is like a line 

of people waiting for a 

bank teller. The queue 

has a front and a rear

$    $ 

Front Rear

Trang 3

rear. The C++ queue class calls this a 

push, although it is usually called an 

enqueue operation

$    $ 

Front Rear

Trang 4

When an item is taken from the queue, 

it always comes from the front.  The 

C++ queue calls this a pop, although it 

is usually called a dequeue operation

$    $ 

Front Rear

Trang 5

template library has 

a queue template 

class

The template 

parameter is the 

type of the items 

that can be put in 

the queue

template <class Item>

class queue<Item>

{ public:

        void push(const Item& entry);         void pop(  );

        Item front(  ) const;

        …

};

Trang 6

A queue can be implemented with an array, as 

shown here.  For example, this queue contains the  integers 4 (at the front), 8 and 6 (at the rear)

An array of integers 

to implement a 

queue of integers

We don't care what's in this part of the array.

Trang 7

track of the number of items in the 

queue and the index of the first 

element (at the front of the queue), the 

last element (at the rear)

3

first

0

last

2

Ngày đăng: 01/04/2021, 17:29

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w