// From the software distribution accompanying the textbook // "A Practical Introduction to Data Structures and Algorithm Analysis, // Third Edition (C++)" by Clifford A. Shaffer. // Source code Copyright (C) 2007-2011 by Clifford A. Shaffer. #include "book.h" // Include permutation function // Randomly permute the "n" values of array "A" template void permute(E A[], int n) { for (int i=n; i>0; i--) swap(A, i-1, Random(i)); } #include "compare.h" // Implementation for heap #include "heap.h" // Test out the heap implementation -- with max heap int main(int argc, char** argv) { int i, j; int n; Int* A[20]; Int* B[20]; Int C[10] = {73, 6, 57, 88, 60, 34, 83, 72, 48, 85}; heap BH(B, 0, 20); heap Test(C, 10, 10); if (argc != 2) { cout << "Usage: heap \n"; exit(-1); } n = atoi(argv[1]); if (n > 20) { cout << "heap size " << n << " too big.\n"; exit(-1); } Randomize(); for (i=0; i AH(A, n, 20); Int* AHval = NULL; for (i=0; i