C++标准库:sort函数(起始位置,终止位置的后一个,升降序方法)

升序降序 sort 排序

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;
#include<vector>	//vector
#include<iostream>  //sout sin
#include<algorithm>	//sort排序算法

bool cmp_down(int a ,int b)//降序函数
{

	return a>b; 
}
bool cmp_up(int a ,int b)//升序函数
{

	return a<b; 
}
void main()
{
	int nums[]={6,7,8,9,5,4,3,2,1,0};
	sort(nums,nums+10,cmp_down);        //起始位置,终止位置的后一个,升降序方法
    for(int i=0; i<10;i++)
        printf("%d ",nums[i]);
}

猜你喜欢

转载自blog.csdn.net/qq1518572311/article/details/80307271