中国高校课件下载中心 》 教学资源 》 大学文库

《数据结构的算法在C++中的应用》(英文版)Chapter 6 Queue

文档信息
资源类别:文库
文档格式:PPT
文档页数:30
文件大小:120.5KB
团购合买:点击进入团购
内容简介
6.1 Definition Definition: A queue is a linear list in which additions and deletions take place at different ends. It is also called a first-in-first-out list. The end at which new elements are added is called the rear. The end from which old elements are deleted is called the front.
刷新页面文档预览

Chapter 6 Q ueue

Chapter 6 Queue

6.1 Definition Definition a queue is a linear list in which additions and deletions take place at different ends It is also called a first-in-first-out list The end at which new elements are added is called the rear The end from which old elements are deleted is called the front

6.1 Definition • Definition: A queue is a linear list in which additions and deletions take place at different ends. It is also called a first-in-first-out list. The end at which new elements are added is called the rear. The end from which old elements are deleted is called the front

6.1 Definition Sample queues front rear front rear front rear AB C B C B C D Delete a Add d

6.1 Definition • Sample queues front rear front rear front rear A B C B C B C D Delete A Add D

6.2 ADT AbstractData Type Queue Instances ordered list of elements one end is called the front the other is the rear operations Create(: Create an empty queue IsEmptyo: Return true if queue is empty, return false otherwise IsFullo return true if queue is full, return false otherwise

6.2 ADT AbstractDataType Queue{ instances ordered list of elements;one end is called the front; the other is the rear; operations Create():Create an empty queue; IsEmpty():Return true if queue is empty,return false otherwise; IsFull():return true if queue is full, return false otherwise;

6.2 ADT Firsto: return first element of the queue Lasto return last element of the queue Add (): add element x to the queue Delete(x): delete front element from the queue and put it in x;

6.2 ADT First():return first element of the queue; Last():return last element of the queue; Add(x):add element x to the queue; Delete(x):delete front element from the queue and put it in x; }

6.3formula-based representation front rear Q Maxsize -1 ueue ABC 0j[1][2] the queue size =rear+ an empty queue has rear--1

6.3formula-based representation the queue size =rear+1; an empty queue has rear=-1 A B C …… Queue: front rear Maxsize-1 [0] [1] [2] [n-1]

6.3formula-based representation To add an element rear-rear+l; queuerear=x; To delete an element: two methods 1)frontfront+1; O( 2)shift the queue one position left. O(n)

6.3formula-based representation To add an element: rear=rear+1; queue[rear]=x; To delete an element: two methods: 1) front=front+1; O(1) 2) shift the queue one position left. O(n)

6.3formula-based representation Figure 6.3 front rear front rear front rear ABC B BIC D

6.3formula-based representation Figure 6.3 front rear front rear front rear A B C … B C … B C D …

6.3formula-based representation Figure 6.4 front rear ABC p Free space

6.3formula-based representation Figure 6.4 … A B C D E Front rear Free space

6.3formula-based representation as the figure6. 4 shows each deletion causes front to move right by 1 So there will be times when rearmaxsize-1 and front>o At these times the queue is not full, there is space at the left end of it

6.3formula-based representation As the figure6.4 shows ,each deletion causes front to move right by 1 So,there will be times when rear=maxsize-1 and front>0 At these times the queue is not full,there is space at the left end of it

共30页,试读已结束,阅读完整版请下载
刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档