当前位置:网站首页>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;
}
}
}
从小到大排序
边栏推荐
- [leetcode daily question 2021/4/29]403. Frogs cross the river
- 2021-08-13和鹏哥学C语言-数组
- Oracle创建索引
- 1748.唯一元素的和
- RT-Thread 学习笔记(七)---开启基于SPI Flash的elmfat文件系统(中)
- 抽象工厂及其改进示例
- winpcap 抓包函数pcap_loop(),停止问题
- Dry goods likeshop takeout order system is open source, 100% open source, no encryption
- [paper after dinner] deep mining external perfect data for chestx ray disease screening
- 【机器学习小记】【搭建循环神经网络及其应用】deeplearning.ai course5 1st week programming(keras)
猜你喜欢
![[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
![[leetcode每日一题2021/4/29]403. 青蛙过河](/img/fb/612777c77df5a611506e72f4f4c3c8.png)
[leetcode每日一题2021/4/29]403. 青蛙过河

Write to esp8266 burning brush firmware

Zongzi battle - guess who can win
![[leetcode daily question 2021/4/29]403. Frogs cross the river](/img/fb/612777c77df5a611506e72f4f4c3c8.png)
[leetcode daily question 2021/4/29]403. Frogs cross the river

Redis docker instance and data structure

Application of.Net open source framework in industrial production

解决:无法加载文件 C:\Users\user\AppData\Roaming\npm\npx.ps1,因为在此系统上禁止运行脚本 。

Dry goods likeshop takeout order system is open source, 100% open source, no encryption
![[leetcode daily question 2021/2/14]765. Lovers hold hands](/img/be/8639a05c733638bf0b3fdeb11abccf.png)
[leetcode daily question 2021/2/14]765. Lovers hold hands
随机推荐
C language callback function
The problem of formatting IAR sprintf floating point to 0.0 in UCOS assembly
STM32 Alibaba cloud mqtt esp8266 at command
IAR sprintf 浮点 在UCOS 总格式化成0.0的问题
剑指Offer(四十四):翻转单词顺序序列
点击el-dropdown-item/@click.native
Issue 8: cloud native -- how should college students learn in the workplace
解决:无法加载文件 C:\Users\user\AppData\Roaming\npm\npx.ps1,因为在此系统上禁止运行脚本 。
Redis special data type usage scenarios
7-25 0-1背包 (50分)
工厂模式详解
粽子大战 —— 猜猜谁能赢
[machine learning notes] [face recognition] deeplearning ai course4 4th week programming
11 handle "self assignment" in operator=
Flutter CachedNetworkImage圆角
Sql Server 数据库之数据类型
构建ARM嵌入式开发环境
Oracle cannot start tnslistener service cannot start
Sql Server 数据库之初学体验
mysql20210906