在c#win中分类数组。形成 [英] Unsorting Array in c# win. form
问题描述
我被困在根据他们的长度对一组整数进行排序并且取消排序的部分。
< b>示例
下面是我想要序列化的整数数组
int [] i = new int [] { 20,5,90,7,44,81};
输出
i = new int [] {5,7,20,90,44,81};
UNSORTING
i = new int [] {20,5,90,7,44,81};
到目前为止,我不能找到一种方法来取消列表的回传。任何代码片段都将不胜感激。
提前致谢
Quote:unsort
不要改变数组 - 使用第一个数组的索引生成另一个数组并更改它 - 这是一种链接列表。
< pre lang =text> int [] i = new int [] {20,5,90,7,44,81};
int [] j = new int [] {1,3,0,2,4,5};
试试这个
int [] i = new int [] { 20 , 5 , 90 , 7 , 44 , 81 };
int [] unsortedarray = new int [i.Length];
i.CopyTo(unsortedarray, 0 );
Array.Sort(i); // 排序数组5,7,20,44,81,90
i = unsortedarray; // 未排序的数组20,5,90,7,44,81
I am stuck at the part of Sorting a group of integers according to their length and Un-Sorting it back.
Example
Below is my integer array that i want to get serialized
int[] i = new int[] { 20,5,90,7,44,81 };
OUTPUT
i = new int[] { 5,7,20,90,44,81 };
UNSORTING
i = new int[] { 20,5,90,7,44,81 };
So far, i cannot find a way to unsort the list back. Any Code snippet would be appreciated.
Thanks in advance
Quote:unsort
Don't alter the array -- make another array with the indices of the first array and alter that -- it's kind of a linked list that way.
int[] i = new int[] { 20,5,90,7,44,81 }; int[] j = new int[] { 1 , 3 , 0 , 2 , 4 , 5 };
Try this
int[] i = new int[] { 20, 5, 90, 7, 44, 81 }; int[] unsortedarray = new int[i.Length]; i.CopyTo(unsortedarray, 0); Array.Sort(i); // sorted array 5,7,20,44,81,90 i = unsortedarray; //un sorted array 20, 5, 90, 7, 44, 81
这篇关于在c#win中分类数组。形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!