int main() { MaxHeap<int> heap; int n=5; cout<<"初始数组大小:"<<n<<endl;; //cin>>n; cout<<"输入的数组:"; //a = new int[n]; int a[6]={0,5,4,11,3,7}; for(int i=1;i<=n;i++) //cin>>a[i]; cout<<a[i]<<" "; cout<<endl; cout<<"初始化为最大堆:"<<endl; heap.Initialize(a,n,100); heap.Output(); cout<<"\n插入10之后的最大堆:\n"; heap.Insert(10); heap.Output(); cout<<"当前堆的大小:"<<heap.Size()<<endl; cout<<"\n删除最大数之后的最大堆:\n"; int b=0; heap.DeleteMax(b); heap.Output(); cout<<"当前堆的大小:"<<heap.Size()<<endl; getchar(); return 0; }
int _tmain(int argc, _TCHAR* argv[]){ MaxHeap<int> myHeap; const int number = 10; int s; int key[10] = { 1, 4, 7, 8, 5, 2, 3, 6, 9, 0 }; ////若要使用键盘输入,把这些注释取消即可 //cout << "请输入10个数:" << endl; //for (int i = 0; i < 10; i++) //{ // cin >> s; // key[i] = s; //} cout << "原数组:" << endl; for (int i = 0; i < 10; i++) cout << key[i] << " "; cout << endl << endl; int myArray[11];//////// for (int i = 0; i < 10; i++) { myArray[i + 1] = key[i]; } myArray[0] = -1; myHeap.Initialize(myArray, number, 20); cout << "最大堆(层序):" << endl; cout << myHeap; HeapSort(myArray, number); cout << "堆排序:" << endl; for (int j = 1; j <= number; j++) { cout << myArray[j] << " "; } cout << endl << endl; cout << "Huffman编码:" << endl; int i; struct node huffmantree; memset(mark, 0, sizeof(mark)); memset(huffman, 0, sizeof(huffman)); for (i = 0; i < 10; i++) { huffman[i].key = key[i]; } huffmantree = HuffmanTree(mark, huffman, 10); cout << "前序:"; PreOrder(&huffmantree); cout << "\n中序:"; MidOrder(&huffmantree); cout << endl << endl; cout << "二叉搜索树:" << endl; struct node *bs; for (int i = 0; i < 10; i++) { bstree[i].key = key[i]; } bs = bstreeinsert(bstree); cout << "前序:"; PreOrder(bs); cout << "\n中序:"; MidOrder(bs);////////中序遍历(二叉搜索树的中序遍历是有序的) cout << endl; system("pause"); return 0; }