collector.cpp

来自「这是一本数据结构C++算法的完整的源代码」· C++ 代码 · 共 43 行

CPP
43
字号
//***************************   collector.cpp   ****************************#include <iostream>#include <cstdlib>using namespace std;#include "heap.h"Heap heap;void program() {    static int val = 123;    int rn, p, q, r;    if (heap.rootCnt == 0) { // call heap.allocateAtom(0,val++);         p = 0;         rn = 1;    }    else {         rn = rand() % 100 + 1;         p  = rand() % heap.rootCnt+1; // possibly new root;         q  = rand() % heap.rootCnt;         r  = rand() % heap.rootCnt;    }    if (rn <= 20)         heap.allocateAtom(p,val++);    else if (rn <= 40)         heap.allocateList(p,q,r);    else if (rn <= 60)         heap.updateHead(q,r);    else if (rn <= 80)         heap.updateTail(q,r);    else heap.deallocate(p);    cout << heap;}int main() {    for (int i = 0; i < 50; i++)        program();    return 0;}

⌨️ 快捷键说明

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