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. 怎么实现这个控件了,我们应当梳理出一个 ...
随机推荐
- touchz,mkdir,vi的区别
touchz:创建空白文档 mkdir:创建一个目录 vi : 创建一个编辑状态的空文档,保存退出后创建成功.
- Kubernetes集群部署(yum部署)
环境准备 Kubernetes-Master:192.168.37.134 #yum install kubernetes-master etcd flannel -y Kubernetes-n ...
- ssh修改默认远程端口
---------------------centos6-----------------1.查看系统版本cat /etc/redhot-releose 2.编辑sshd配置,修改默认的端口vim / ...
- ICEM-空心圆柱体
原视频下载地址:https://pan.baidu.com/s/1boG49MB 密码: 4iq6
- MAC 隐藏功能
finder 类: shift+ cmd + G (去指定路径) cmd+↑ (返回) cmd+↓(打开当前选中的文件,如果没有选中的则去选中第一个) cmd+ o (打开当前选中的文件) 以下这些 ...
- tomcat启动报错java.lang.OutOfMemoryError:PermGen space解决办法
tomcat启动错误提示: 严重: Error waiting for multi-thread deployment of WAR files to completejava.util.concur ...
- 《恶魔人crybaby》豆瓣短评爬取
作业要求来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/3159 爬虫综合大作业 选择一个热点或者你感兴趣的主题. 选择爬取的对象 ...
- Web前端开发规范之图片命名规范
图片的名称分为头尾两部分,用下划线隔开,头部表示此图片的大类性质,例如广告,标志,菜单,按钮等 banner:放置在页面顶部的广告,装饰图案等长方形的图片 logo:标志性的图片 button:在页面 ...
- [Angular] ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'name' of undefined
在数据请求完成通过 ionViewDidLoad 展示页面的时候 报错误 : ERROR Error: Uncaught (in promise): TypeError: Cannot read pr ...
- [转发]for 循环,jQuery循环遍历详解
1.for 循环原生JS最基本的使用: for (var i=0;i<cars.length;i++) { ..... } for - 循环代码块一定的次数2.for infor/in - 循环 ...