C# 数组排序带索引
想到了两种方法来实现,分别利用了List.Sort()和Dictionary.OrderBy()方法,代码如下:
int[] arrInt = new int[] { , , , , , , , , , };
//List.Sort()
List<int> lstOrg = new List<int>(), lstSort = new List<int>();
lstOrg.AddRange(arrInt);
lstSort.AddRange(arrInt);
lstSort.Sort();
List<int> lstIndex = new List<int>();
for (int i = ; i < lstSort.Count; i++)
{
int index = lstOrg.IndexOf(lstSort[i]);
while (lstIndex.IndexOf(index) >= )
{
index = lstOrg.IndexOf(lstSort[i], index + );
}
lstIndex.Add(index);
Console.Write("({0},{1})", index, lstSort[i]);
}
Console.ReadLine();
int[] arrInt = new int[] { , , , , , , , , , };
//Dictionary.OrderBy()
Dictionary<int, int> dic = new Dictionary<int, int>();
for (int i = ; i < arrInt.Length; i++)
{
dic.Add(i, arrInt[i]);
}
dic = dic.OrderBy(o => o.Value).ToDictionary(p => p.Key, o => o.Value);
foreach (var item in dic)
{
Console.Write("({0},{1})", item.Key, item.Value);
}
Console.ReadLine();
输出正常!
总觉得应该有很方便的方法来实现,奈何想不出来。。。
C# 数组排序带索引的更多相关文章
- 带索引的tableView
带索引的tableView 一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface Root ...
- jQuery仿3D旋转木马效果插件(带索引按钮)
项目中需要用到旋转木马效果,但是我在网上找的插件,基本都是不带按钮或者只是带前后按钮的,而项目要求的是带索引按钮,也就是说有3张图片轮播,对应的要有3个小按钮,点击按钮,对应的图片位于中间位置.于是就 ...
- Android带索引联系人列表
网上Android联系人列表的样例也非常多,都和微信的联系人差点儿相同,因为项目用到了联系人列表索引功能(产品把字母item给去掉了),只是也还是好实现.这里我也来分享分享我的实现,免得以后忘了.那先 ...
- List带索引的常用方法,以及集合的三种遍历
package cn.learn.collection.List; import com.sun.source.tree.NewArrayTree; import java.util.ArrayLis ...
- Python3基础 list(enumerate()) 将一个列表的每一个元素转换成 带索引值的元组
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- Python3基础 list enumerate 将列表的每个元素转换成 带索引值的元组
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- ngFor 循环带索引
*ngFor="let item of userList,let i = index" 或者 *ngFor="let item of userList index a ...
- 3D游戏引擎设计 实时计算机图形学的应用方法 第2版 pdf 带索引书签目录
3D游戏引擎设计 实时计算机图形学的应用方法 第2版 目录 第1章 概述1.1 图形硬件和游戏发展史1.2 本书版本与软件发展史1.3 章节导读 第2章 图形系统2.1 基础知识2.1.1 坐标系 ...
- 老猪带你玩转android自定义控件二——自定义索引栏listview
带索引栏的listview,在android开发非常普遍,方便用户进行字母索引,就像微信通讯录这样: 今天,我们就从零到一实现这个具有索引栏的listview. 怎么实现这个控件了,我们应当梳理出一个 ...
随机推荐
- 升级项目版本:SpringBoot1.5.x到SpringBoot2.0.x
1.升级版本的选择 首先去spring的官网看一下最新的版本与版本之间的依赖
- EXCEL复制可见单元格
Excel筛选后,复制筛选后的单元格 1, 首先还是复制这一部分内容. 2, CTRL+G打开 "定位"窗口. 3, 在 "定位"窗口中选择"定位条件 ...
- VS2019(NET Core 3.0)发布单文件可执行程序
NET Core 3.0 发布单文件可执行程序 两种方法. 一.右击vs编辑项目文件,增加PublishSingleFile节点配置,代码如下: <Project Sdk="Micro ...
- ROS tf-深入Time和TF
博客转载自:https://www.ncnynl.com/archives/201702/1313.html ROS与C++入门教程-tf-深入Time和TF 说明: 介绍使用waitForTrans ...
- tomcat乱码解决
一.修改Tomcat的conf的server.xml文件加上 URIEncoding="UTF-8" 二.在tomcat的bin 目录下的catalina.bat 配置文件中,添加 ...
- [Matplotlib] Data Representation
Jupyter Notebook Goto: https://plot.ly/python/#3d-charts[丰富的作图资源] Data Visualization¶ In [1]: from ...
- 移动端播放直播流(video.js 播放 m3u8 流)
流媒体服务器: wowza 流媒体格式: m3u8 播放端:移动端网页(Android.IOS) 播放工具: video.js 代码如下: <!DOCTYPE html> <html ...
- [LeetCode] 765. Couples Holding Hands 情侣牵手
N couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum numb ...
- linux : 各个发行版中修改python27默认编码为utf-8
该方法可解决robot报错:'ascii' codec can't encode character u'\xf1' in position 16: ordinal not in range(128 ...
- Kubernetes & Docker 容器网络终极之战(十四)
目录 一.单主机 Docker 网络通信 1.1.host 模式 1.2 Bridge 模式 1.3 Container 模式 1.4.None 模式 二.跨主机 Docker 网络通信分类 2.1 ...