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

📄 xhpsel.cpp

📁 这是数学计算上常用的计算方法
💻 CPP
字号:
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
#include "nr.h"
using namespace std;

// Driver for routine hpsel

int main(void)
{
        const int NP=100;
        string txt;
        int i,k;
        DP check;
        Vec_DP a(NP);
        ifstream fp("tarray.dat");

        if (fp.fail())
          NR::nrerror("Data file tarray.dat not found");
        getline(fp,txt);
        for (i=0;i<NP;i++) fp >> a[i];
        cout << fixed << setprecision(2);
        for (;;) {
          cout << endl << "Input heap size (or 0 to end)" << endl;
          cin >> k;
          if (k < 1 || k >= NP) break;
          Vec_DP heap(k);
          NR::hpsel(a,heap);
          check=NR::select(NP-k,a);
          cout << "heap[0], check= " << setw(6) << heap[0];
          cout << setw(6) << check << endl;
          cout << "heap of numbers of size " << k << endl;
          for (i=0;i<k;i++)
            cout << setw(2) << i << setw(8) << heap[i] << endl;
        }
        cout << "Normal completion" << endl;
        return 0;
}

⌨️ 快捷键说明

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