0
点赞
收藏
分享

微信扫一扫

几处排序函数

瑾谋 2023-09-15 阅读 16


c快速排序qsort
int cmp(const void * a,const void * b){
    int * aa=(int *)a;
    int * bb=(int *)b;
    return (*aa)-(*bb);
}按从小到大排列!


c++中sort函数


template <class RandomAccessIterator> void sort ( RandomAccessIterator first, RandomAccessIterator last ); template <class RandomAccessIterator, class Compare> void sort ( RandomAccessIterator first, RandomAccessIterator last, Compare comp );


Parameters


first, last [first,last), which contains all the elements between first and

last, including the element pointed by

first but not the element pointed by

last.

comp true if the first argument goes before the second argument in the specific strict weak ordering it defines, and false otherwise.


bool cmp (int i,int j) { return (i<j); }   //定义从小到大的顺序



c++ priority_queue

通过操作,按照元素从大到小的顺序出队

struct Status  
{  
    int ti;  
    int di;  
    bool operator <(const Status a)const  
    {  
        return ti<a.ti;  
    }  
}trap[N],now,temp;  
priority_queue<Status>q;





举报

相关推荐

0 条评论