• 周六. 8月 20th, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

堆排序 使用 algorithm

admin

11月 28, 2021

简介

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

发表回复

您的电子邮箱地址不会被公开。