如何在c#中描述arraye?交换的替换是什么? [英] how to describe arraye in c#? what is the replacement of swap ?
本文介绍了如何在c#中描述arraye?交换的替换是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Program
{
static Thread t1;
static Thread t2;
static ThreadStart ts1;
static ThreadStart ts2;
public static void insertion_sort1()
{
for (int i = 1; i <= 50; i++)
{
int j = i;
while (j != 0 && A[j - 1] > A[j])
{
swap(j - 1, j);
j--;
}
}
}
public static void insertion_sort2()
{
for (int i = 51; i <= 100; i++)
{
int j = i;
while (j != 0 && A[j - 1] > A[j])
{
swap(j - 1, j);
j--;
}
}
}
static void Main(string[] args)
{
ts1 = new ThreadStart(insertion_sort1);
ts2 = new ThreadStart(insertion_sort2);
t1 = new Thread(ts1);
t2 = new Thread(ts2);
t1.Start();
t2.Start();
}
}
}
推荐答案
你可以像这样描述一个数组:
You can describe an array like this:
来自MSDN的引用: [ ^ ]
数组是一个数据结构,包含许多称为数组元素的变量。通过计算索引访问数组元素。
An array is a data structure that contains a number of variables called the elements of the array. The array elements are accessed through computed indexes.
C#中的数组没有内置的交换方法。你必须自己创建一个,如下所示:
There is no built-in swap method for arrays in C#. You have to create one yourself, like this:
public static void Swap(int[] array, int i1, int i2)
{
int temp = array[i1];
array[i1] = array[i2];
array[i2] = temp;
}
i1
和 i2
代表你要交换的元素的索引。
i1
and i2
represent the indices of the elements you want to swap.
这篇关于如何在c#中描述arraye?交换的替换是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文