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. 怎么实现这个控件了,我们应当梳理出一个 ...
随机推荐
- mybatis or的用法
@Test public void test3(){ CaseSmallListExample caseSmallListExample = new CaseSmallListExample(); c ...
- java中&& 的运算优先级高于||
public class First { public static void main(String[] args) { boolean a = false; boolean b = true; b ...
- 如何使用git把本地代码上传(更新)到github上
最近用到git和github记录一下 1.下载git并安装 到官网下载并安装就行了 *如果下载失败,或者太慢,可以复制链接到迅雷下载 2.上传 1.在github新建存储库 库名不能是中文 2.在需要 ...
- 第06组 Beta冲刺(3/5)
队名:拾光组 组长博客链接 作业博客链接 团队项目情况 燃尽图(组内共享) 组长:宋奕 过去两天完成了哪些任务 继续维护后端代码 学习深入python 研究匿名拨打电话问题.套牌多结果处理问题 Git ...
- 2019_软工实践_Beta(2/5)
队名:955 组长博客:点这里! 作业博客:点这里! 组员情况 组员1(组长):庄锡荣 过去两天完成了哪些任务 文字/口头描述 ?按照时间进度的安排进行相应的检查 展示GitHub当日代码/文档签入记 ...
- HIDL概述【转】
本文转载自:https://blog.csdn.net/u013357557/article/details/84561457 HIDL背景Treble 是 Google Android 团队的一项重 ...
- Java_jdbc 基础笔记之十一数据库连接 (通用的查询方法)
鉴于之前的查询方法,在这里我们可以写一个通用的方法 /** * 鉴于 student.和customer查询的方法有好多相同之处,在此可以写一个通用的方法 */ public <T> T ...
- 【Nginx】Nginx服务器配置调优
1.Nginx服务器配置调优 .设置nginx全局参数 vi /usr/local/nginx/conf/nginx.conf #编辑 worker_processes ; # 工作进程数,为CPU的 ...
- openresty开发系列34--openresty执行流程之4访问阶段
openresty开发系列34--openresty执行流程之4访问阶段 访问阶段 用途:访问权限限制 返回403 nginx:allow 允许,deny 禁止 allow ip:deny ip: 涉 ...
- 暚光科技定位系统数据解析-java
暚光科技定位系统数据解析-java package com.ygkj.test; import java.io.DataInputStream; import java.io.IOException; ...