从0开始学算法--排序(1.12c++利用标准库排序)
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++利用标准库排序)的更多相关文章
- 从0开始学爬虫10之urllib和requests库与github/api的交互
urllib库的使用 # coding=utf-8 import urllib2 import urllib # htpbin模拟的环境 URL_IP="http://10.11.0.215 ...
- 0算法基础学算法 搜索篇第二讲 BFS广度优先搜索的思想
dfs前置知识: 递归链接:0基础算法基础学算法 第六弹 递归 - 球君 - 博客园 (cnblogs.com) dfs深度优先搜索:0基础学算法 搜索篇第一讲 深度优先搜索 - 球君 - 博客园 ( ...
- freeRTOS V10.0.1移植到STM32F407标准库 - 环境Keil5
最近因为工作需要用到FreeRTOS,其实开始本人内心是拒绝的因为自己只学习过UCOSIII还没实际上过什么大又复杂的工程,但是谁让FreeRTOS他是Free的呢公司成本考虑肯定是不会选择USOS的 ...
- 《OD学算法》排序
参考 http://www.cnblogs.com/kkun/archive/2011/11/23/2260312.html http://blog.csdn.net/wuxinyicomeon/ar ...
- 看动画学算法之:排序-count排序
目录 简介 count排序的例子 count排序的java实现 count排序的第二种方法 count排序的时间复杂度 简介 今天我们介绍一种不需要作比较就能排序的算法:count排序. count排 ...
- 几种排序算法的学习,利用Python和C实现
之前学过的都忘了,也没好好做过总结,现在总结一下. 时间复杂度和空间复杂度的概念: 1.空间复杂度:是程序运行所以需要的额外消耗存储空间,一般的递归算法就要有o(n)的空间复杂度了,简单说就是递归集算 ...
- 决策树之ID3、C4.5、C5.0等五大算法
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- C5.0决策树之ID3.C4.5.C5.0算法 ...
- 1187: 零起点学算法94——今年暑假不AC(Java)
1187:零起点学算法94--今年暑假不AC Time Limit: 1 Sec Memory Limit: 32 MB 64bit IO Format: %lld Description " ...
- STL笔记(6)标准库:标准库中的排序算法
STL笔记(6)标准库:标准库中的排序算法 标准库:标准库中的排序算法The Standard Librarian: Sorting in the Standard Library Matthew A ...
随机推荐
- const与指针、引用
const与指针类型 定义一个指针*p: const int* p = NULL; int const* p = NULL; int* const p = NULL; 上面两行定义完全等价,第三行则不 ...
- fish 设置环境变量;fish shell 相关使用说明记录;
最近使用 fish进行工作,发现环境变量忘记如何设置: fish 环境变量保存在两个地方: ~ 目录下,.config/fish 目录下: /etc/fish/ 目录下 如果配置所有用户都能用的环境变 ...
- c# 异步编程 使用回调函数例子
环境VS2010, 在项目属性中输出类型选择控制台应用程序 运行结果 using System;using System.Collections.Generic;using System.Compon ...
- 剑指offer-面试题61-扑克牌中的顺子-数组
/* 题目: 从扑克牌中随机抽取n个数字,判断他们是否连续,扑克牌从A~K,大小王可代替任意数字. */ #include<iostream> #include<cstdlib> ...
- cobaltstrike使用笔记2
0x01 cs服务端绕过流量检测 定义C2的通信格式,修改CS默认的流量特征 编写Profiles: 开源Profiles:https://github.com/rsmudge/Malleable-C ...
- 10maven依赖继承、统一版本/编码
A > B > C A依赖于B,B依赖于C,如果A想间接依赖C,那么B和C之间的依赖范围必须是compile,不然A依赖不了C 但是有点麻烦,因为每次A想依赖于C都要确认B和C之间的 ...
- 将String类型的json数据转换为真正的json数据
问题 在做JavaWeb项目的时候,我们经常需要将Java对象转化为Json数据格式响应到前台页面,但是转化完成之后,看着是Json类型的数据格式,但实际上是字符串类型,在这里说两个方法将String ...
- Jenkins+robotframework持续集成环境(一)
一.安装JDK 系统环境:CentOS Linux release 7.3.1611 x86_64 GNU/Linux Jenkins是基于Java开发的持续集成系统(CI),所以运行环境必须安装JD ...
- 星星评分-依赖jquery
https://pan.baidu.com/s/1UWJFh-QJOjSB_yqA8VgHIQ
- const 函数
const int *p // 修饰*p ,p指针可以变,但是*p的值不变 例子: int a = 5; int b = 10; const *p = &a; *p = 10: // 不可 ...