1. cmake_minimum_required(VERSION 3.5)
  2. project(Test)
  3.  
  4. add_executable( te test.cpp )

test.cpp

  1. #include <stdlib.h>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <fstream>
  5. using namespace std;
  6. int main()
  7. {
  8. int test[] = {}; // 全都赋值为0
  9. for(int i = ; i < ; i++)
  10. {
  11. cout << test[i] << endl;
  12. test[i]++;
  13.  
  14. }
  15. std::cout << "=======================" << std::endl;
  16. for (int j = ; j < ; j++)
  17. {
  18. std::cout << test[j] << std::endl;
  19. }
  20. return ;
  21. }

执行结果:

  1.  
  2. =======================

sort

sort.cpp

  1. #include <iostream>
  2. #include <array>
  3. #include <algorithm>
  4. #include "opencv2/imgproc/imgproc.hpp"
  5. #include "opencv2/highgui/highgui.hpp"
  6.  
  7. using namespace std;
  8.  
  9. struct Line{ // 大写
  10. cv::Point2i p1, p2;
  11. };
  12.  
  13. bool compare(int a, int b)
  14. {
  15. return a < b;
  16. }
  17.  
  18. bool cpr(Line l1, Line l2){
  19. return l1.p2.y > l2.p2.y;
  20. }
  21.  
  22. int main() {
  23. std::array<int, > s = { , , , , , , , , , };
  24.  
  25. sort(s.begin(), s.end(), compare);
  26. for (auto a : s) {
  27. std::cout << a << " ";
  28. }
  29. std::cout << '\n' << '\n';
  30.  
  31. vector<Line> lines;
  32. Line l1, l2;
  33. l1.p1 = cv::Point2i(, );
  34. l1.p2 = cv::Point2i(, );
  35.  
  36. lines.push_back(l1);
  37.  
  38. l2.p1 = cv::Point2i(, );
  39. l2.p2 = cv::Point2i(, );
  40. lines.push_back(l2);
  41. cout << "排序前:" << endl;
  42. for (auto & l : lines){
  43. cout << l.p1.x << " " << l.p1.y << " " << l.p2.x << " " << l.p2.y << endl;
  44. }
  45.  
  46. sort(lines.begin(), lines.end(), cpr);
  47. cout << "排序后:" << endl;
  48. for (auto & l : lines){
  49. cout << l.p1.x << " " << l.p1.y << " " << l.p2.x << " " << l.p2.y << endl;
  50. }
  51.  
  52. return ;
  53. }

CMakeLists.txt

  1. cmake_minimum_required(VERSION 3.9)
  2. project(sort)
  3.  
  4. set(CMAKE_CXX_STANDARD )
  5. FIND_PACKAGE(OpenCV REQUIRED)
  6.  
  7. add_executable(sort main.cpp)
  8. TARGET_LINK_LIBRARIES(sort ${OpenCV_LIBS})

执行结果:

  1.  
  2. 排序前:
  3.  
  4. 排序后:
  5.  
  6. 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. oracle数据链接

    using System; using System.Collections.Generic; using System.Data; using System.Data.OracleClient; u ...

  2. 离线部署 pm2

    1. install nodejs curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash - 2.安装pm ...

  3. suse linux安装lrzsz

    1.从下面的网站下载 lrzsz-1.12.20.tar.gz http://www.filewatcher.com/m/lrzsz-0.12.20.tar.gz.280938.0.0.html 2. ...

  4. 2017-11-04 Sa OCT codecombat

    def hasEnemy(): e = hero.findNearestEnemy() if e: return True else: return False def enemyTooClose() ...

  5. 利用python的requests发送http请求

    >>> from requests import put, get >>> put('http://localhost:5000/todo1', data={'da ...

  6. DOM 扩展

    1.选择符API,selectors API 可以使用CSS选择符匹配查找节点 1)  querySelector(selector),接受一个CSS选择符,返回调用该函数的节点后代中第一个匹配的元素 ...

  7. python 网络内容: 初识socket

    一 C\S架构,客户端服务端架构 客户端(client) : 享受服务端提供的服务 服务端(server) : 给客户端提供服务 B\S 浏览器和服务端 B(browser) 二 网络通信的整个流程( ...

  8. [leetcode]34.Find First and Last Position of Element in Sorted Array找区间

    Given an array of integers nums sorted in ascending order, find the starting and ending position of ...

  9. angularJs, ui-grid 设置默认group, 及排序

  10. 写jsp文件时需要注意的一些小细节

    ①jsp文件的最开始的部分: <%@ page language="java" contentType="text/html; charset=UTF-8" ...