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. 怎么实现这个控件了,我们应当梳理出一个 ...
随机推荐
- Codeforces 839D Winter is here - 暴力 - 容斥原理
Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n s ...
- (二)Cisco dhcp snooping配置解释
#配置dhcp snooping相关命令 Switch(config)#ip dhcp snooping //打开DHCP Snooping功能Switch(config)#ip dhcp snoo ...
- es6学习2:变量的解构赋值
一:数组的解构赋值 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构 let [foo, [[bar], baz]] = [1, [[2], 3]]; foo bar ba ...
- Web前端开发规范 之html命名规范
1.文件名称命名规则 统一用小写的英文字母.数字和下划线,不得包含汉字空格和特殊符号 2.索引文件命名 一般用index为名字 如index.html index.jsp 3.各子页面的命名规则 ...
- SpringBoot dev-tools vjtools dozer热启动类加载器不相同问题
最近使用唯品会的vjtools的BeanMapper进行对象的深度克隆转换DTO/VO这种操作,Spring Boot的dev-tools热启动,需要把vjtools和dozer包都放到spring- ...
- 如何使用Salt Pillar
作者言 Salt的网站上有两篇关于Pillar的文档(一,二),其中一篇内容很少,我觉得写成一篇文章更合适.本文的逻辑结构没有参照官方文档,而是根据我自己对Pillar的理解组织内容,希望能够把这个概 ...
- java excel给单元格增加批注(包含SXSSF)
package javatest; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi ...
- [转]css3自适应布局单位vw,vh你知道多少?
原文地址:https://www.cnblogs.com/luxiaoxing/p/7544375.html 视口单位(Viewport units) 什么是视口? 在PC端,视口指的是在PC端,指的 ...
- Ubuntu 配置镜像源
Ubuntu 配置镜像源 注, 如果添加镜像后没有自己要安装的软件, 切回原镜像即可, 只是有点慢. cp /etc/apt/sources.list /etc/apt/sources.list.ba ...
- EasyNVR网页Chrome无插件播放摄像机视频功能二次开发之云台控制接口示例代码
随着多媒体技术和网络通信技术的迅速发展,视频监控技术在电力系统.电信行业.工业监控.工地.城市交通.水利系统.社区安防等领域得到越来越广泛的应用.摄像头直播视频监控通过网络直接连接,可达到的世界任何角 ...