当前位置:网站首页>list升序和降序
list升序和降序
2022-07-26 10:41:00 【Lovey_北禾】
升序
sort
list.sort把数组进行升序排序
num.Sort();
for (int i = 0; i < k; i++)
{
result.Add(num[i]);
}
降序
sort
list.sort 那数组进行升序排序
翻转遍历
num.Sort();
for (int i = k; i > 0; i--)
{
result.Add(num[i]);
}
以上是利用sort进行,下面的方法麻烦就是把sort的方法拆解成具体的代码
冒泡排序
for (int i = 0; i < arr.Length; i++)
{
for (int j = i; j < arr.Length; j++)
{
if (arr[i] > arr[j])
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
从小到大排序
边栏推荐
- 【机器学习小记】【人脸识别】deeplearning.ai course4 4th week programming
- A semicolon is missing
- Flutter TextField设置高度并且自动换行,圆角边框去除下划线
- MD5 encryption
- 第8期:云原生—— 大学生职场小白该如何学
- [leetcode每日一题2021/4/29]403. 青蛙过河
- Add touch screen driver for stemwin 5.22 on Shenzhou IV development board
- Problems encountered in QRcode QR code (C language)
- 27.移除元素
- 剑指Offer(二十):包含min函数的栈
猜你喜欢
![[leetcode daily question 2021/4/23]368. Maximum divisible subset](/img/0b/32ca862963c842a93f79eaac94fb98.png)
[leetcode daily question 2021/4/23]368. Maximum divisible subset

反射机制简述

Add touch screen driver for stemwin 5.22 on Shenzhou IV development board
![[dectectron2] follow the official demo](/img/aa/03e46897234c309415b336ac39b7d9.png)
[dectectron2] follow the official demo

Redis docker instance and data structure

el-table实现可编辑表格

抽象工厂及其改进示例

PLC与伺服电机连接
![[leetcode daily question 2021/2/18] [detailed explanation] minimum number of turns of 995. K continuous bits](/img/de/62fca587cde95110c2a967ca93eea5.png)
[leetcode daily question 2021/2/18] [detailed explanation] minimum number of turns of 995. K continuous bits

Centos8 (liunx) deploying WTM (asp.net 5) using PgSQL
随机推荐
20210807#1 C语言程序结构
Redis implementation of distributed lock solution
SAP ABAP 守护进程的实现方式
Flutter报错 Incorrect use of ParentDataWidget When the exception was thrown, this was the stack:
【机器学习小记】【搭建循环神经网络及其应用】deeplearning.ai course5 1st week programming(keras)
Issue 8: cloud native -- how should college students learn in the workplace
Flutter TextField设置高度并且自动换行,圆角边框去除下划线
[dectectron2] follow the official demo
12 don't forget every component when copying an object
[转]ArcGIS中判断两个Geometry之间的关系
控制随机抽中几率 [ C# | Random ]
构建ARM嵌入式开发环境
RT thread learning notes (I) -- configure RT thread development environment
RT-Thread 学习笔记(一)---配置RT-Thread开发环境
C language calculation date interval days
flutter dart生成N个区间范围内不重复随机数List
mysql20210906
剑指Offer(四十三):左旋转字符串
RT-Thread 学习笔记(三)---用SCons 构建编译环境
Halcon模板匹配之Shape