当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

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

资源类别:文库,文档格式:PPT,文档页数:36,文件大小:111.5KB,团购合买
9.1 Introduction A priority queue is a collection of zero or more elements. Each element has a priority or value.
点击下载完整版文档(PPT)

Chapter 9 Priority Queues

Chapter 9 Priority Queues

9.1 Introduction a priority queue is a collection of zero or more elements. Each element has a priority or value Operations I)find an element 2)insert a new element 3)delete an element

9.1 Introduction • A priority queue is a collection of zero or more elements. Each element has a priority or value. • Operations: 1)find an element 2)insert a new element 3)delete an element

9.1 Introduction In a min priority queue the find operation finds the element with minimum priority. while the delete operation delete this element In a max priority queue, the find operation finds the element with maximum priority while the delete operation delete this element

9.1 Introduction • In a min priority queue the find operation finds the element with minimum priority, while the delete operation delete this element. • In a max priority queue, the find operation finds the element with maximum priority, while the delete operation delete this element

9.1 Introduction ADT of a max priority queue AbstractData Type Max Priority Queue Instances finite collection of elements. each has a priority operations create(: create an empty priority queue Sizeo: return number of element in the queue Max(: return element with maximum priority Insert(x) insert x into queue DeleteMax(x): delete the element with largest priority from the queue, return it in X

9.1 Introduction • ADT of a max priority queue AbstractDataType MaxPriorityQueue{ instances finite collection of elements,each has a priority operations create(): create an empty priority queue Size(): return number of element in the queue Max(): return element with maximum priority Insert(x): insert x into queue DeleteMax(x):delete the element with largest priority from the queue;return it in x; }

9.2 Linear List representation Use an unordered linear list Insertions are performed at the right end of the list, A(1) a deletion requires a search for the element with largest priority, A(n)

9.2 Linear List Representation • Use an unordered linear list • Insertions are performed at the right end of the list, θ(1) • A deletion requires a search for the element with largest priority, θ(n)

9.3 Heaps 1. definition: A max heap(min Heap) is a complete binary tree The value in each node is greater(less)than or equal to those in its children(if any)

9.3 Heaps 1.definition: A max heap(min Heap) • is A complete binary tree • The value in each node is greater(less) than or equal to those in its children(if any)

9.3 Heaps For example: an max heap k={87,78,53456509,31,1723} 87 78 650931

9.3 Heaps • For example:an max heap k={87,78,53,45,65,09,31,17,23} 87 78 45 65 53 09 17 31 23

9.3 Heaps Example of min heap k={09,1765,2345,78875331} 09 0765 3)4578⑧7 53)(31

9.3 Heaps • Example of min heap k={09,17,65,23,45,78,87,53,31} 09 17 23 45 65 78 53 87 31

9.3 Heaps class M ahEap Data member of heap T* heap; int MaxSize, currentsize templateclass Maxheap i public MaxHeap(int MaxHeap Size=10); MaxHeapoidelete[heap int sizeOconst(return currentsize

9.3 Heaps 2.class MaxHeap Data member of heap: T * heap; int MaxSize, currentSize templateclass Maxheap { public: MaxHeap(int MaxHeapSize=10); ~MaxHeap(){delete[]heap;} int size()const{return currentSize;}

9.3 Heaps T Maxfif( Currentsize==O)throw OutofBoundso: return heap[1]; j MaxHeap &insert(const T&x) MaxHeap& deleteMax(t& x) void initialize(t all, int size, int Array Size); private int CurrentSize, Maxsize T* heap

9.3 Heaps T Max(){if (CurrentSize==0)throw OutOfBounds(); return heap[1];} MaxHeap&insert(const T&x); MaxHeap& DeleteMax(T& x); void initialize(T a[], int size, int ArraySize); private: int CurrentSize, MaxSize; T * heap; }

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共36页,可试读12页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有