84template <
class T,
class T1>
87 std::vector< std::array<int,2> >*map_
111 use_labels = flag_label;
134template <
class T,
class T1>
138 std::vector< std::array<int,2> >*map_
162 use_labels = flag_label;
180template <
class T,
class T1>
207 if (use_labels) { labels.clear(); }
222template <
class T,
class T1>
242 if (use_labels) { labels.resize(MAXSTK); }
252template <
class T,
class T1>
272 keys.resize(heap_size + MAXSTK);
276 labels.resize(heap_size + MAXSTK);
287template <
class T,
class T1>
288void MinPQueue<T, T1>::decreaseSTACK(
307 keys.resize(std::max(n - MAXSTK, MAXSTK));
311 labels.resize(std::max(n - MAXSTK, MAXSTK));
323template <
class T,
class T1 >
324void MinPQueue<T, T1>::heapify(
333 int L, R, idummy, imap;
349 if ((L < heap_size) && (keys[L] < keys[i])) {
355 if ((R < heap_size) && (keys[R] < keys[idummy])) {
362 keys[i] = keys[idummy];
363 keys[idummy] = dummy;
366 labels[i] = labels[idummy];
367 labels[idummy] = dummy2;
371 (*map)[i][0] = (*map)[idummy][0];
372 (*map)[idummy][0] = imap;
373 (*map)[(*map)[i][0]][1] = i;
374 (*map)[(*map)[idummy][0]][1] = idummy;
386template <
class T,
class T1>
404 for (i = (heap_size - 1)/2; i >= 0; i--) {
421template <
class T,
class T1>
442 if (heap_size == 0) {
448 keys[0] = keys[heap_size-1];
450 root_label = labels[0];
451 labels[0] = labels[heap_size-1];
455 (*map)[0][0] = (*map)[heap_size-1][0];
456 (*map)[heap_size-1][0] = imap;
457 (*map)[imap][1] = heap_size-1;
458 (*map)[(*map)[0][0]][1] = 0;
463 if (heap_size <= (
long) keys.size() - MAXSTK) {
481template <
class T,
class T1>
501 if (heap_size == 0) {
507 keys[0] = keys[heap_size-1];
510 (*map)[0][0] = (*map)[heap_size-1][0];
511 (*map)[heap_size-1][0] = imap;
512 (*map)[imap][1] = heap_size-1;
513 (*map)[(*map)[0][0]][1] = 0;
518 if (heap_size <= keys.size() - MAXSTK) {
537template <
class T,
class T1>
558 if (heap_size+1 > (
long) keys.size()) {
563 keys[heap_size] = key_new;
567 labels[heap_size] = label_new;
574 modify(heap_size-1, key_new, label_new);
586template <
class T,
class T1>
622 if (heap_size+1 > keys.size()) {
627 keys[heap_size] = key_new;
633 modify(heap_size-1, key_new);
648template <
class T,
class T1>
670 if (key_new > keys[i]) {
675 labels[i] = label_new;
687 labels[i] = label_new;
692 while ((i > 0) && (keys[j] > keys[i])) {
698 labels[i] = labels[j];
703 (*map)[i][0] = (*map)[j][0];
705 (*map)[(*map)[i][0]][1] = i;
706 (*map)[(*map)[j][0]][1] = j;
724template <
class T,
class T1>
744 if (key_new > keys[i]) {
760 while ((i > 0) && (keys[j] > keys[i])) {
766 (*map)[i][0] = (*map)[j][0];
768 (*map)[(*map)[i][0]][1] = i;
769 (*map)[(*map)[j][0]][1] = j;
786template <
class T,
class T1>
806 out <<
"min heap:" << std::endl;
807 out <<
"heap size: " << heap_size << std::endl;
808 out <<
"data struct. size: " << keys.size() << std::endl;
809 out <<
"max stack size: " << MAXSTK << std::endl;
812 out <<
"min heap data:" << std::endl;
815 while (i < heap_size) {
817 while ((j <
pow(2, k)) && (i < heap_size)) {
818 out <<
"[" << keys[i];
820 out <<
", '" << labels[i] <<
"'";
886template <
class T,
class T1>
889 std::vector< std::array<int,2> >*map_
913 use_labels = flag_label;
936template <
class T,
class T1>
940 std::vector< std::array<int,2> >*map_
964 use_labels = flag_label;
982template <
class T,
class T1>
1025 if (use_labels) { labels.clear(); }
1040template <
class T,
class T1>
1059 keys.resize(MAXSTK);
1060 if (use_labels) { labels.resize(MAXSTK); }
1070template <
class T,
class T1>
1090 keys.resize(heap_size + MAXSTK);
1094 labels.resize(heap_size + MAXSTK);
1105template <
class T,
class T1>
1106void MaxPQueue<T, T1>::decreaseSTACK(
1131 int n = keys.size();
1141 keys.resize(std::max(n - MAXSTK, MAXSTK));
1145 labels.resize(std::max(n - MAXSTK, MAXSTK));
1157template <
class T,
class T1 >
1158void MaxPQueue<T, T1>::heapify(
1167 int L, R, idummy, imap;
1183 if ((L < heap_size) && (keys[L] > keys[i])) {
1189 if ((R < heap_size) && (keys[R] > keys[idummy])) {
1196 keys[i] = keys[idummy];
1197 keys[idummy] = dummy;
1200 labels[i] = labels[idummy];
1201 labels[idummy] = dummy2;
1204 imap = (*map)[i][0];
1205 (*map)[i][0] = (*map)[idummy][0];
1206 (*map)[idummy][0] = imap;
1207 (*map)[(*map)[i][0]][1] = i;
1208 (*map)[(*map)[idummy][0]][1] = idummy;
1220template <
class T,
class T1>
1254 for (i = (heap_size - 1)/2; i >= 0; i--) {
1271template <
class T,
class T1>
1292 if (heap_size == 0) {
1298 keys[0] = keys[heap_size-1];
1300 root_label = labels[0];
1301 labels[0] = labels[heap_size-1];
1304 imap = (*map)[0][0];
1305 (*map)[0][0] = (*map)[heap_size-1][0];
1306 (*map)[heap_size-1][0] = imap;
1307 (*map)[imap][1] = heap_size-1;
1308 (*map)[(*map)[0][0]][1] = 0;
1313 if (heap_size <= (
long) keys.size() - MAXSTK) {
1331template <
class T,
class T1>
1351 if (heap_size == 0) {
1357 keys[0] = keys[heap_size-1];
1359 imap = (*map)[0][0];
1360 (*map)[0][0] = (*map)[heap_size-1][0];
1361 (*map)[heap_size-1][0] = imap;
1362 (*map)[imap][1] = heap_size-1;
1363 (*map)[(*map)[0][0]][1] = 0;
1368 if (heap_size <= keys.size() - MAXSTK) {
1387template <
class T,
class T1>
1408 if (heap_size+1 > (
long) keys.size()) {
1413 keys[heap_size] = key_new;
1417 labels[heap_size] = label_new;
1424 modify(heap_size-1, key_new, label_new);
1436template <
class T,
class T1>
1456 if (heap_size+1 > keys.size()) {
1461 keys[heap_size] = key_new;
1467 modify(heap_size-1, key_new);
1482template <
class T,
class T1>
1504 if (key_new < keys[i]) {
1509 labels[i] = label_new;
1521 labels[i] = label_new;
1526 while ((i > 0) && (keys[j] < keys[i])) {
1532 labels[i] = labels[j];
1536 imap = (*map)[i][0];
1537 (*map)[i][0] = (*map)[j][0];
1538 (*map)[j][0] = imap;
1539 (*map)[(*map)[i][0]][1] = i;
1540 (*map)[(*map)[j][0]][1] = j;
1558template <
class T,
class T1>
1578 if (key_new < keys[i]) {
1594 while ((i > 0) && (keys[j] < keys[i])) {
1599 imap = (*map)[i][0];
1600 (*map)[i][0] = (*map)[j][0];
1601 (*map)[j][0] = imap;
1602 (*map)[(*map)[i][0]][1] = i;
1603 (*map)[(*map)[j][0]][1] = j;
1620template <
class T,
class T1>
1640 out <<
"max heap:" << std::endl;
1641 out <<
"heap size: " << heap_size << std::endl;
1642 out <<
"data struct. size: " << keys.size() << std::endl;
1643 out <<
"max stack size: " << MAXSTK << std::endl;
1646 out <<
"max heap data:" << std::endl;
1649 while (i < heap_size) {
1651 while ((j <
pow(2, k)) && (i < heap_size)) {
1652 out <<
"[" << keys[i];
1654 out <<
", '" << labels[i] <<
"'";
class for max priority queue.
void display(std::ostream &)
MaxPQueue(bool a=false, std::vector< std::array< int, 2 > > *b=NULL)
class for min priority queue.
void display(std::ostream &)
MinPQueue(bool a=false, std::vector< std::array< int, 2 > > *b=NULL)
std::array< T, d > pow(std::array< T, d > &x, double p)