# algorithm ch6 priority queque

```int  HeapMaximum(int a[], int &heapSize)
{
return a[1];
}
int HeapExtractMax(int a[], int &iHeapSize)
{
if(iHeapSize < 1)
{
cout << "heap underflow." << endl;
}
int iMax = a[1];
a[1] = a[iHeapSize];
iHeapSize = iHeapSize - 1;
MaxHeapify(a, 1, iHeapSize);
return iMax;
}
void HeapIncreaseKey(int a[], int iPos, int iKey)
{
if(iKey < a[iPos])
{
cout << "new key is smaller than current key." << endl;
return;
}
a[iPos] = iKey;
while(iPos > 1 && a[parent(iPos)] < a[iPos])
{
swap(a[iPos], a[parent(iPos)]);
iPos = parent(iPos);
}
}
void MaxHeapInsert(int a[], int iKey, int &iHeapSize)
{
iHeapSize += 1;
a[iHeapSize] = -INT_MAX;
HeapIncreaseKey(a, iHeapSize, iKey);
}```

## Algorithm Part I:Priority Queues

1.binary heap实现 BinaryHeap.h #ifndef BINARYHEAP_H #define BINARYHEAP_H class BinaryHeap { public: BinaryHeap(int N); bool isEmpty(); void exchange(int i,int j); void insert(int key); int delMax(); int getMax(); virtual ~BinaryHeap(); protected: priva

## Linux: the schedule algorithm in Linux kernel

Linux kernel里面用到的一个叫 CFS (Completely-Fair-Scheduler)的调度算法.在网上找的描述都很不直观,很难读.但是找到了一篇很通俗易懂的(大道至简啊...): http://people.redhat.com/mingo/cfs-scheduler/sched-design-CFS.txt 为了防止链接失效,粘贴全文如下: This is the CFS scheduler. 80% of CFS's design can be summed up in

## 优先队列(堆) Priority Queue

Priority Queue Definition & Description: In computer science/data structures, a priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated wi

## Non-blocking algorithm(非阻塞算法，非阻塞同步的算法实现)

Non-blocking algorithm In computer science, a non-blocking algorithm ensures that threads competing for a shared resource do not have their execution indefinitely postponed by mutual exclusion. A non-blockingalgorithm is lock-free if there is guarant

## Algorithm | Sort

Bubble sort Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wron

## Heap &amp;amp; Priority Queue

Heap & Priority Queue Definition & Description: In computer science/data structures, a priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" as