将数组中指定数量的元素移动数组后面的实现代码
作者:
本篇文章是对将数组中指定数量的元素移动数组后面的实现代码进行了详细的分析介绍,需要的朋友参考下
如下所示:
static void Main()
{
int[] array = { 1, 2, 3, 4, 5, 6, 7 };
MoveNumberArrayToEnd(array, 3);
}
static void MoveNumberArrayToEnd<T>(IList<T> arrayList, int num)
{
if (arrayList.Count < = 0 || arrayList.Count < num)
{
throw new RankException();
}
var query = (from number in arrayList
orderby number descending
select number).Take(arrayList.Count - num).Concat(arrayList.Take(num));
query.ToList().ForEach(q => Console.WriteLine("{0}", q));
}
复制代码 代码如下:
static void Main()
{
int[] array = { 1, 2, 3, 4, 5, 6, 7 };
MoveNumberArrayToEnd(array, 3);
}
static void MoveNumberArrayToEnd<T>(IList<T> arrayList, int num)
{
if (arrayList.Count < = 0 || arrayList.Count < num)
{
throw new RankException();
}
var query = (from number in arrayList
orderby number descending
select number).Take(arrayList.Count - num).Concat(arrayList.Take(num));
query.ToList().ForEach(q => Console.WriteLine("{0}", q));
}