当前位置:网站首页>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;
}
}
}
从小到大排序
边栏推荐
- 访问权限——private,public,protected
- Issue 5: the second essential skill for College Students
- 12 don't forget every component when copying an object
- SAP ABAP 守护进程的实现方式
- The problem of large fluctuation of hx711 data
- MySQL速学-2021-09-01
- Sql Server 数据库之数据类型
- 在神州IV开发板上成功移植STemWin V5.22
- RT thread learning notes (I) -- configure RT thread development environment
- sigmod 函数与softmax 函数对比
猜你喜欢
![[leetcode daily question 2021/5/8]1723. The shortest time to complete all work](/img/e7/a48bb5b8a86cbc4cd5b37bb16661a8.png)
[leetcode daily question 2021/5/8]1723. The shortest time to complete all work

多目标优化系列1---NSGA2的非支配排序函数的讲解

GIS方法类期刊和论文的综述(Introduction)怎么写?

反射机制简述
![[machine learning notes] [face recognition] deeplearning ai course4 4th week programming](/img/7e/9c0e88097b90c0c24ebf86f090805b.png)
[machine learning notes] [face recognition] deeplearning ai course4 4th week programming

Analysis of the transaction problem of chained method call

2021-08-12函数递归_和鹏哥学习C语言

按二进制数中1的个数分类

【机器学习小记】【风格迁移】deeplearning.ai course4 4th week programming(tensorflow2)

344.反转字符串
随机推荐
Sql Server 数据库之数据类型
MD5 encryption
oracle 启动不了 tnslistener服务启动不了
Centos8 (liunx) deploying WTM (asp.net 5) using PgSQL
Uninstall Meizu app store
Problems encountered in QRcode QR code (C language)
[leetcode每日一题2021/2/18]【详解】995. K 连续位的最小翻转次数
剑指Offer(五):用两个栈实现队列
按二进制数中1的个数分类
剑指Offer(九):变态跳台阶
Flutter TextField怎样去除下划线及有焦点时颜色
11 handle "self assignment" in operator=
JS对象赋值问题
第8期:云原生—— 大学生职场小白该如何学
Sql Server 之SQL语句对基本表及其中的数据的创建和修改
RT-Thread 学习笔记(六)--- 开启基于SPI Flash的elmfat文件系统(上)
【机器学习小记】【风格迁移】deeplearning.ai course4 4th week programming(tensorflow2)
Asynctask < T> decoration and await are not used in synchronous methods to obtain asynchronous return values (asynchronous methods are called in synchronous methods)
Redis docker instance and data structure
创建EOS账户 Action