当前位置:网站首页>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每日一题2021/2/13]448. 找到所有数组中消失的数字](/img/9b/624416fa6a408bf64ca5438273176b.png)
[leetcode每日一题2021/2/13]448. 找到所有数组中消失的数字

粽子大战 —— 猜猜谁能赢

Phase 4: one of College Students' vocational skills preparation in advance

mysql20210906

第6期:大学生应该选择哪种主流编程语言

第8期:云原生—— 大学生职场小白该如何学

344.反转字符串

Dry goods likeshop takeout order system is open source, 100% open source, no encryption

The problem of large fluctuation of hx711 data

第5期:大学生入职必备技能之二
随机推荐
PLC与伺服电机连接
flutter 背景变灰效果,如何透明度,灰色蒙板遮罩
关于硕博士开题报告编写的思考
抽象工厂及其改进示例
【小程序】onReachBottom 事件为什么不能触发 ?(一秒搞定)
RT thread learning notes (I) -- configure RT thread development environment
RT-Thread 学习笔记(八)---开启基于SPI Flash的elmfat文件系统(下)
Flutter报错 Incorrect use of ParentDataWidget When the exception was thrown, this was the stack:
Issue 5: the second essential skill for College Students
Problems encountered in QRcode QR code (C language)
Analysis of the transaction problem of chained method call
Simple use of json-c Library -- converting JSON files to struct
json_ object_ put: Assertion `jso->_ ref_ count > 0‘ failed. Aborted (core dumped)
点击el-dropdown-item/@click.native
Add touch screen driver for stemwin 5.22 on Shenzhou IV development board
[machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)
解决:无法加载文件 C:\Users\user\AppData\Roaming\npm\npx.ps1,因为在此系统上禁止运行脚本 。
鹏哥C语言第七节课总结
剑指Offer(五十三):表示数值的字符串
[leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]