cmake_minimum_required(VERSION 3.5)
project(Test) add_executable( te test.cpp )

test.cpp

 #include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <fstream>
using namespace std;
int main()
{
int test[] = {}; // 全都赋值为0
for(int i = ; i < ; i++)
{
cout << test[i] << endl;
test[i]++; }
std::cout << "=======================" << std::endl;
for (int j = ; j < ; j++)
{
std::cout << test[j] << std::endl;
}
return ;
}

执行结果:


=======================

sort

sort.cpp

 #include <iostream>
#include <array>
#include <algorithm>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp" using namespace std; struct Line{ // 大写
cv::Point2i p1, p2;
}; bool compare(int a, int b)
{
return a < b;
} bool cpr(Line l1, Line l2){
return l1.p2.y > l2.p2.y;
} int main() {
std::array<int, > s = { , , , , , , , , , }; sort(s.begin(), s.end(), compare);
for (auto a : s) {
std::cout << a << " ";
}
std::cout << '\n' << '\n'; vector<Line> lines;
Line l1, l2;
l1.p1 = cv::Point2i(, );
l1.p2 = cv::Point2i(, ); lines.push_back(l1); l2.p1 = cv::Point2i(, );
l2.p2 = cv::Point2i(, );
lines.push_back(l2);
cout << "排序前:" << endl;
for (auto & l : lines){
cout << l.p1.x << " " << l.p1.y << " " << l.p2.x << " " << l.p2.y << endl;
} sort(lines.begin(), lines.end(), cpr);
cout << "排序后:" << endl;
for (auto & l : lines){
cout << l.p1.x << " " << l.p1.y << " " << l.p2.x << " " << l.p2.y << endl;
} return ;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.9)
project(sort) set(CMAKE_CXX_STANDARD )
FIND_PACKAGE(OpenCV REQUIRED) add_executable(sort main.cpp)
TARGET_LINK_LIBRARIES(sort ${OpenCV_LIBS})

执行结果:


排序前:

排序后:

Process finished with exit code 

C++数组,sort的更多相关文章

  1. javascript:算法之数组sort排序

    数组sort排序 sort比较次数,sort用法,sort常用 描述 方法sort()将在原数组上对数组元素进行排序,即排序时不创建新的数组副本.如果调用方法sort()时没有使用参数,将按字母顺序( ...

  2. js数组sort排序方法的算法

    说明一下,ECMAScript没有定义使用哪种排序算法,各个浏览器的实现方式会有不同.火狐中使用的是归并排序,下面是Chrome的sort排序算法的实现. sort方法源码 DEFINE_METHOD ...

  3. JS数组Sort方法的使用

    想用sort方法对数组排下序,代码如下: var nums = "12 645 6 85 81 0 9 365 4 752".split(" ").map(fu ...

  4. jquery数组(sort() 排序)

    HTML: <h3>字符串数组排序前</h3> <div id="show5"></div> <h3>排序后</h ...

  5. JS数组sort比较函数

    转载:http://www.cnblogs.com/ljchow/archive/2010/06/30/1768683.html 我们知道,数组的sort方法可以对数组元素进行排序,默认是按ASCII ...

  6. 二维数组sort排序

    和副本任务完全无关的奇怪感慨: 完全搞不懂我为什么会在搞图论的时候学这种奇怪东西,需要的时候不会,不需要的时候又莫名增加了奇怪的技能点. 之前的假期规划在十多天的放飞自我中彻底泡汤,简单的图论都一点不 ...

  7. js数组sort方法详解

    在处理数组的时候,我们有时候需要对数组进行排序,排序的方法有很多种,但是最好最快的就是利用sort方法进行快速的排序. 我们来看一个例子: var arr1 = [6, 3, 4, 1, 2, 5, ...

  8. js数组sort()排序的问题

    最近跟自以为很了解的数组干上了,就像许多我们认知的东西一样,总以为自己很了解的东西,其实并不了解. var a=[12,4,1,43,5,3,52];  alert(a);   //源:12,4,1, ...

  9. js 数组sort, 多条件排序。

    Array.sort(); sort()方法可以传入一个函数作为参数,然后依据该函数的逻辑,进行数组的排序. 一般用法:(数组元素从小大进行排序) var a = [9, 6, 5, 7, 11, 5 ...

  10. LeetCode 912. 排序数组(Sort an Array) 43

    912. 排序数组 912. Sort an Array 题目描述 每日一算法2019/6/15Day 43LeetCode912. Sort an Array

随机推荐

  1. tcp中delay_ack的理解

    内核版本,3.10. 首先,我们需要知道,在一个sock中,维护ack的就有很多变量,多种状态: struct inet_connection_sock { .... __u8 icsk_ca_sta ...

  2. ImportError: No module named pycocotools.coco,pycocotools/_mask.so: undefined symbol: _Py_ZeroStruct

    准确的说是没有安装 pycocotools 可以借鉴下面链接: https://blog.csdn.net/ab0902cd/article/details/79085797 因为我通常用Python ...

  3. quick pdf library控件

    quick pdf library库只能在windows环境下运行 1.下载quick pdf library 2.注册控件 进入cmd  regsvr32 "C:\Program File ...

  4. python学习笔记(五)- 文件操作

    1.读文件f = open('word.txt',encoding='utf8')  #默认打开当前目录下的文件,打开其它目录用绝对路径#f = open('word.txt',encoding='u ...

  5. 在ASP.NET中使用KindEditor富文本编辑器

    以前一直用百度的UEditor.这次客户提了一个需求要在编辑器中插入Flash动画,但是不知道怎么用UEditor实现,于是选用了KindEditor. 更重要的一点是,客户的网站使用Framewor ...

  6. 深入JVM之类的加载过程

    类的加载—连接—初始化 加载:查找并加载类的字节码文件,从硬盘到内存. 类的加载指的是将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法区内,然后在堆区创建一个java.la ...

  7. rhce 第十一题 挂载NFS共享

    挂载NFS共享 在system2上挂载一个来自 system1.group8.example.com 的NFS共享,并符合下列要求: /public 挂载在/mnt/nfsmount目录上 /prot ...

  8. mysql 的 select into 带来的错误数据问题

    在写存储过程的时候,会有一个被忽视的问题: 比如 select user_name into @user_name from user where id = 1; 会出现 其实没有 id =1 这条数 ...

  9. 【轻松前端之旅】​CSS选择器中的空格与尖括号有何区别?

    CSS选择器中的空格与尖括号有何区别? 例子1: .a .b { margin: 0; } 空格隔开a和b,选择所有后代元素. 例子2: .a>.b { margin: 0; } 尖括号隔开a和 ...

  10. Linux安装yum

    方法/步骤 1 查看.卸载已安装的yum包 查看已安装的yum包 #rpm –qa|grep yum 卸载软件包 #rpm –e –nodeps yum 2 下载安装依赖包python python- ...