将数组中指定数量的元素移动数组后面的实现代码
程序员文章站
2024-02-13 15:26:04
如下所示:复制代码 代码如下: static void main() &nbs...
如下所示:
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));
}