Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<;中make_heap()函数的算法;算法>; 我只是在C++中用MaxyHeAPP()函数进行实验。下面是我通过打印跟踪每次调用bool predicate()时所比较的元素的代码 #include <iostream> #include <algorithm> using namespace std; // bool predicate function to make a min heap bool predicate(int a, int b){ cout << a << " " << b << endl; if(a >= b){ return 1; } return 0; } int main(){ int arr[] = {3,2,1,-1,-2}; make_heap(arr, arr+5, predicate); return 0; } #包括 #包括 使用名称空间std; //用于生成最小堆的布尔谓词函数 布尔谓词(int a,int b){ cout_C++_Algorithm_Stl_Heap_Predicates - Fatal编程技术网

<;中make_heap()函数的算法;算法>; 我只是在C++中用MaxyHeAPP()函数进行实验。下面是我通过打印跟踪每次调用bool predicate()时所比较的元素的代码 #include <iostream> #include <algorithm> using namespace std; // bool predicate function to make a min heap bool predicate(int a, int b){ cout << a << " " << b << endl; if(a >= b){ return 1; } return 0; } int main(){ int arr[] = {3,2,1,-1,-2}; make_heap(arr, arr+5, predicate); return 0; } #包括 #包括 使用名称空间std; //用于生成最小堆的布尔谓词函数 布尔谓词(int a,int b){ cout

<;中make_heap()函数的算法;算法>; 我只是在C++中用MaxyHeAPP()函数进行实验。下面是我通过打印跟踪每次调用bool predicate()时所比较的元素的代码 #include <iostream> #include <algorithm> using namespace std; // bool predicate function to make a min heap bool predicate(int a, int b){ cout << a << " " << b << endl; if(a >= b){ return 1; } return 0; } int main(){ int arr[] = {3,2,1,-1,-2}; make_heap(arr, arr+5, predicate); return 0; } #包括 #包括 使用名称空间std; //用于生成最小堆的布尔谓词函数 布尔谓词(int a,int b){ cout,c++,algorithm,stl,heap,predicates,C++,Algorithm,Stl,Heap,Predicates,我不会说有一个足够标准化的算法,这样你就可以期望执行一组特定的比较了。标准化的是算法的复杂性,只要比较的次数是线性的,你就可以去做。而且,似乎stl的性能比你更好在比较的数量方面,所以你不应该担心 正如注释中所建议的那样,您可以随时阅读编译器使用的std::make_heap实现的代码,但不能保证相同的实现将用于stl的所有实现。您有实现的make_heap的模板源。是否有预先准备的通过C++实现“ MaxyHeope>代码>通过最小比较来生成堆,是否需要进行更多的比较?

我不会说有一个足够标准化的算法,这样你就可以期望执行一组特定的比较了。标准化的是算法的复杂性,只要比较的次数是线性的,你就可以去做。而且,似乎
stl
的性能比你更好在比较的数量方面,所以你不应该担心


正如注释中所建议的那样,您可以随时阅读编译器使用的
std::make_heap
实现的代码,但不能保证相同的实现将用于
stl
的所有实现。您有实现的
make_heap
的模板源。是否有预先准备的通过C++实现“<代码> MaxyHeope>代码>通过最小比较来生成堆,是否需要进行更多的比较?