8template <
class Type>
class Queue {
22 void reheapUp(
int,
int);
23 void reheapDown(
int,
int);
24 void swap(Type *&, Type *&);
30 static const int incSize = 10;
42 arr =
new Type *[size];
57 int temp_size = size + incSize;
58 Type **temp_arr =
new Type *[temp_size];
60 for (
int i = 0; i < size; ++i) {
70 reheapUp(0, tail - 1);
76 cout <<
"pop gagal!" << endl;
81 arr[0] = arr[tail - 1];
83 reheapDown(0, tail - 1);
90 cout <<
"pop gagal!" << endl;
100 return (tail >= size);
108 parent = (bottom - 1) / D;
110 if (*arr[parent] > *arr[bottom]) {
111 swap(arr[parent], arr[bottom]);
112 reheapUp(root, parent);
119 int minChild, firstChild, child;
121 firstChild = root * D + 1;
123 if (firstChild <= bottom) {
124 minChild = firstChild;
126 for (
int i = 2; i <= D; ++i) {
127 child = root * D + i;
128 if (child <= bottom) {
129 if (*arr[child] < *arr[minChild]) {
135 if (*arr[root] > *arr[minChild]) {
136 swap(arr[root], arr[minChild]);
137 reheapDown(minChild, bottom);