⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prg13_1.cpp

📁 经典数据结构书籍 数据结构C++语言描述 的源代码 很难找的哦
💻 CPP
字号:
#include <iostream.h>
#pragma hdrstop

#include "heap.h"

// print the  array of n elements
template <class T>
void PrintList (T A[], int n)
{   
    for(int i=0;i < n;i++)
        cout << A[i] << "  ";
    cout << endl;
}

void main(void)
{
    // initialized array of 10 elements
    int A[10] = {50, 20, 60, 65, 15, 25, 10, 30, 4, 45};

    cout << "Initial array:" << endl;
    PrintList(A,10);

    // declare a heap that binds array A as its list    
    Heap<int>  H(A,10);
    
    // print the heapified version of array A
    cout << "Heapified array:" << endl;
    PrintList(A,10);
    
    cout << "Deleting elements from the heap:" << endl;
    // repeatedly extract smallest value
    while(!H.ListEmpty())
        cout << H.Delete() << "  ";
    cout << endl;
}

/* 
<Run of Program 13.1>

Initial array:
50  20  60  65  15  25  10  30  4  45  
Heapified array:
4  15  10  20  45  25  60  30  65  50  
Deleting elements from the heap:
4  10  15  20  25  30  45  50  60  65  
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -