1,简单数组按升序排序

sort(a,a+n);
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue> using namespace std; const int maxn=1e5+;
int a[maxn];
int n; int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=;i<n;i++){
printf("%d ",a[i]);
}printf("\n");
return ;
}

2.简单数组降序排序

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue> using namespace std; const int maxn=1e5+;
int a[maxn];
int n; bool complare(int a,int b){
return a>b;
} int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n,complare);
for(int i=;i<n;i++){
printf("%d ",a[i]);
}printf("\n");
return ;
}

3.结构体排序

struct node{
int a,b;
double c;
}an[maxn]; bool cmp(node x,node y){
if(x.a!=y.a)return x.a<y.a;
if(x,b!=y.b)return x.b>y.b;
return x.c<y.c;
}
sort(an,an+n,cmp);

4.vector排序

sort(v.begin(),v.end());

5.vector结构体排序

struct job{
int j,b;
bool operator<(cost job &x)const{
return j>x.j;
}
};
vector<job>v;
sort(v.begin(),v.end);

从0开始学算法--排序(1.12c++利用标准库排序)的更多相关文章

  1. 从0开始学爬虫10之urllib和requests库与github/api的交互

    urllib库的使用 # coding=utf-8 import urllib2 import urllib # htpbin模拟的环境 URL_IP="http://10.11.0.215 ...

  2. 0算法基础学算法 搜索篇第二讲 BFS广度优先搜索的思想

    dfs前置知识: 递归链接:0基础算法基础学算法 第六弹 递归 - 球君 - 博客园 (cnblogs.com) dfs深度优先搜索:0基础学算法 搜索篇第一讲 深度优先搜索 - 球君 - 博客园 ( ...

  3. freeRTOS V10.0.1移植到STM32F407标准库 - 环境Keil5

    最近因为工作需要用到FreeRTOS,其实开始本人内心是拒绝的因为自己只学习过UCOSIII还没实际上过什么大又复杂的工程,但是谁让FreeRTOS他是Free的呢公司成本考虑肯定是不会选择USOS的 ...

  4. 《OD学算法》排序

    参考 http://www.cnblogs.com/kkun/archive/2011/11/23/2260312.html http://blog.csdn.net/wuxinyicomeon/ar ...

  5. 看动画学算法之:排序-count排序

    目录 简介 count排序的例子 count排序的java实现 count排序的第二种方法 count排序的时间复杂度 简介 今天我们介绍一种不需要作比较就能排序的算法:count排序. count排 ...

  6. 几种排序算法的学习,利用Python和C实现

    之前学过的都忘了,也没好好做过总结,现在总结一下. 时间复杂度和空间复杂度的概念: 1.空间复杂度:是程序运行所以需要的额外消耗存储空间,一般的递归算法就要有o(n)的空间复杂度了,简单说就是递归集算 ...

  7. 决策树之ID3、C4.5、C5.0等五大算法

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- C5.0决策树之ID3.C4.5.C5.0算法 ...

  8. 1187: 零起点学算法94——今年暑假不AC(Java)

    1187:零起点学算法94--今年暑假不AC Time Limit: 1 Sec Memory Limit: 32 MB 64bit IO Format: %lld Description " ...

  9. STL笔记(6)标准库:标准库中的排序算法

    STL笔记(6)标准库:标准库中的排序算法 标准库:标准库中的排序算法The Standard Librarian: Sorting in the Standard Library Matthew A ...

随机推荐

  1. C# checked unchecked

    static void CheckedUnCheckedDemo() { int i = int.MaxValue; try { //checked //{ // Console.WriteLine( ...

  2. 通过HTML和CSS1:1还原风暴英雄官方网站

    <!--HTML代码--> <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  3. nginx基础(一)

    一.nginx的安装.启动.停止及文件解读 yum -y install gcc gcc-c++ autoconf pcre-devel make automake yum -y install wg ...

  4. html文件如何下载文件

    HTML中下载文件两种方法:a标签下载:js下载; <!-- 网页地址和图片地址同源的情况下这样是可以的,不同源则是直接打开这个地址 --> <!-- 方法一:同源情况下载 --&g ...

  5. Lucene之查询索引

    Query子类 TermQuery:根据域和关键词进行搜索 /** * termQuery根据域和关键词进行搜索 */ @Test public void termQuery() throws IOE ...

  6. rabbitmq安装(ubuntu)

    本文大量复制自:https://blog.csdn.net/qq_22638399/article/details/81704372 # 安装erlang apt-get install erlang ...

  7. JS中变量、作用域的本质,定义及使用方法

    全局作用域和局部作用域 全局作用域 局部作用域:函数作用域 全局作用域在全局和局部都可以访问到,局部作用域只能在局部被访问到 var name="cyy"; function fn ...

  8. [转]Android Adapter以及getView()方法的理解

    Android Adapter基本理解: 我的理解是: 1.一个有许多getter的类(就是getView(),getCount()....这些方法) 2.有多少个get方法?都是什么? 这些gett ...

  9. Android中动态改变Listview中字体的颜色

    效果如下: 账目显示用的是Listview,要实现的功能为使其根据所在Item是“收入”还是“支出”来把数字设置成绿色或红色 方法是自定义适配器,并重写其中getView()函数,实现如下: //自定 ...

  10. 第2章 在 HTML中 使用 JavaScript

    第2章 在 HTML中 使用 JavaScript 2.1 script 元素 2.1.1 标签的位置 2.1.2 延迟脚本 2.1.3 异步脚本 2.1.4 在XHTML中的使用 2.1.5 不推荐 ...