優先順序佇列

2021-05-26 05:28:02 字數 1577 閱讀 6911

1:  #include "stdafx.h"
2:  #include
3:
4:  

using

namespace std;

5:
6:  

#define max_heap_len 10

7:  

int heap[max_heap_len];

8:  

int heap_size = 0; // the number of elements in heaps

9:
10:  

void swap(int* a, int* b)

11:
17:
18:  

void shift_up(int i)

19:
28:  

else

29:
32:          i = (i-1)/2;
33:      }
34:  }
35:
36:  

void shift_down(int i)

37:
48:  

if (heap[(i-1)/2] < heap[i])

49:
52:  

else

53:
56:      }
57:  }
58:
59:  

/*

60:  

void mydelete(int i)

61:  

*/

72:
73:  

int dequeue()

74:
82:
83:  

void insert(int new_data)

84:
90:
91:
92:  

int _tmain(int argc, _tchar* argv)

93:  ;
95:  

for(int i=0; i<10; i++)

96:          insert(input[i]);
97:
98:  

for(int i=0; i<10; i++)

99:          cout<" ";
100:
101:      cout<102:
103:  

for(int i=0; i<10; i++)

104:          cout<" ";
105:
106:      system("pause");
107:      

return 0;

108:  }

佇列 優先順序佇列

優先順序佇列的隊尾是不需要改變的,永遠在低下標處。當佇列增加資料時,隊頭的位置就是資料項的大小減去1.public class priorityq 插入 public void insert long item else quearray j 1 item nitem 刪除 public long ...

優先順序佇列

分為最小優先順序佇列和最大優先順序佇列。優先順序佇列是一種用來維護一組元素構成的集合s的資料結構,這一組元素都有乙個關鍵字key,乙個最大優先順序佇列支援的操作 insert s,x 把x插入到集合s中 maxmum s 返回s中最大元素 extra max s 去掉s中最大關鍵字並返回該最大關鍵子...

優先順序佇列

堆乙個很常見的應用 作為高效的優先順序佇列。如堆一樣,佇列也有兩種 最大優先順序佇列和最小優先順序佇列。優先順序佇列是一種用來維護由一組元素構成的集合s的資料結構,這一組元素中的每乙個都有乙個關鍵字key。乙個最大優先順序佇列支援以下操作 最大優先順序佇列的乙個應用是在一台分時計算機上進行作業排程。...