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. 怎么实现这个控件了,我们应当梳理出一个 ...
随机推荐
- web 视频播放器clappr 相关
https://github.com/tjenkinson/clappr-thumbnails-plugin/ https://github.com/andrefilimono/clappr-flvj ...
- fillter根据value来匹配字段
字段对应 let cashBackState = { 'WAIT_FIVE': '满5单可返现', 'FINISHED': '已返现' } filters: { cashBackStateFilter ...
- idea docker docker-compose发布springboot站点到tomcat
允许docker被远程访问 见:https://www.cnblogs.com/wintersoft/p/10921396.html 教程:https://spring.io/guides/gs/sp ...
- 搭建高可用rabbitmq集群及spring boot实现集群配置
java spring boot配置: //具体参看了配置的源码 org.springframework.boot.autoconfigure.amqp.RabbitProperties //Rabb ...
- plsql 使用desc命令提示invalid sql statement
使用SQL WINDOW运行desc命令就报invalid sql statement错误!! 使用Command Window就可以!!!
- Spring Boot方式的Dubbo项目
项目依赖 需要org.apache.dubbo.dubbo-dependencies-bom, 需要org.apache.dubbo.dubbo-spring-boot-starter, 当前版本有2 ...
- 迁移Git项目到Gitlab
假定Gitlab已经安装, 假定要迁移的Git项目目录为 demo 首先在Gitlab里创建一个新的project, 名称为demo (或者其他名称都可以) 然后在现有的Git项目目录下, 进行以下操 ...
- python的super深入了解(转)
1.python的继承以及调用父类成员 python子类调用父类成员有2种方法,分别是普通方法和super方法 假设Base是基类 class Base(object): def __init__(s ...
- [转]C++ 使用 curl 进行 http 请求(GET、POST、Download)的封装
原文连接:https://www.cnblogs.com/oftenlin/p/9478067.html CommonTools.h /* * CommonTools.h * * Created ...
- Android 解读Event和Main Log
1 Android P EventLogTags文件 Android P 9.0.0 所有EventLogTags文件List: system/bt/EventLogTags.logtags syst ...