堆排序 使用 algorithm

简介

show code

code

#include <set>
#include <vector>
#include <list>
#include <iostream>
#include <memory> 
#include <algorithm>
using namespace std;
int main() {
    vector<int> a = {1, 2, 3, 4, 8, 6};
    make_heap(a.begin(), a.end());
    sort_heap(a.begin(), a.end());
    cout <<"
";
    for(auto it:a) std::cout << it << " ";
    make_heap(a.begin(), a.end());
    cout <<"
";
    for(auto it:a) std::cout << it << " ";
    a.push_back(7);
    push_heap(a.begin(), a.end());
    cout <<"
";
    for(auto it:a) std::cout << it << " ";

}
Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/15025867.html