和C#的冒泡排序法 的逻辑一致,本文不再赘述。
使用?:表达式来代替 一个 IF语句,也比较容易。
代码如下所示
void JudgeArraySequence()
{
int[] IntArray = { 3, 2, 6, 1, 5, 4 };
int x, y,z;
for (int i = 0; i < IntArray.Length ;i++)
{
// IntArray[i];
for (int j = 0; j < IntArray.Length; j++)
{
x = (IntArray[i] > IntArray[j]) ? i : j;//Compare the size of the two integer values. X equal to the index of the larger array of the two.
y = IntArray[x];//Y equal to the value of the larger array.
z = IntArray[i];
IntArray[i] = IntArray[x];
IntArray[x] = z;
}//end for j
}//end for i
Debug.Log(" "+IntArray[0]+ " " + IntArray[1]+ " " + IntArray[2] + " " + In