连接两个列表和根据第一个列表对连接列表进行排序. [英] Concatenate Two List & sort concatenated list on the basis of first List.
问题描述
并置两个列表并在第一个列表的基础上对并置列表进行排序.
假设第一个列表数据为:
清单1 = [21]
[24]
[23]
[26]
假设第二个列表数据为:
清单2 = [21]
[32]
[38]
[26]
[25]
串联后的List1和List2,即
List3 = [21]
[24]
[23]
[26]
[21]
[32]
[38]
[26]
[25]
我的查询是我想要这种方式排序后的列表结果:-
List3 = [21]
[21]
[24]
[23]
[26]
[26]
[32]
[38]
[25]
Concatenate Two List & sort concatenated list on the basis of first List.
Suppose First List Data is :
List1 = [21]
[24]
[23]
[26]
Suppose Second List Data is :
List2 = [21]
[32]
[38]
[26]
[25]
List1 and List2 after concatenation i.e
List3 = [21]
[24]
[23]
[26]
[21]
[32]
[38]
[26]
[25]
My query is I want result of the list after sorting in this Fashion : -
List3= [21]
[21]
[24]
[23]
[26]
[26]
[32]
[38]
[25]
推荐答案
其中一些链接可能会有所帮助-
http://www.cs.nyu.edu/~vs667/articles/mergesort/ [ ^ ]
http://www.java2s.com/Tutorial/C/0140__Array/Mergingoftwosortedlists.htm [ ^ ]
http://en.csharp-online.net/Merge_Sort [
Some of these links might help -
http://www.cs.nyu.edu/~vs667/articles/mergesort/[^]
http://www.java2s.com/Tutorial/C/0140__Array/Mergingoftwosortedlists.htm[^]
http://en.csharp-online.net/Merge_Sort[^]
ArrayList al = new ArrayList();
for (int i = 0; i < ListBox1.Items.Count; i++)
{
al.Add(ListBox1.Items[i].ToString());
}
for (int i = 0; i < ListBox2.Items.Count; i++)
{
al.Add(ListBox2.Items[i].ToString());
}
al.Sort();
for (int i = 0; i < al.Count; i++)
{
ListBox3.Items.Add(al[i].ToString());
}
试试这个
Hi ,
Try this
IList<int> List1 = new List<int>() { 5, 7, 1, 4 };
IList<int> List2 = new List<int>() { 3, 11, 9, 2 };
IList<int> Result = List1.Union(List2).OrderBy(p => p).ToList<int>();
这篇关于连接两个列表和根据第一个列表对连接列表进行排序.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!