代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace F3
{
class Program
{
static void Main(string[] args)
{
int[] array = { 1, 2, 6, 9, 4, 7, 13, 12, 5, 3, 8, 10, 11 };
int temp = 0;
for(int i=0;i<=array.Length-1;i++)
{
for(int j=0; i<array.Length-1-i;j++)
{
if(array[j]>array[j+1])
{
temp=array[j+1];
array[j+1]=array[j];
array[j]=temp;
}
}
}
int size = 0;
while (size < array.Length)
{ //输出排序后的数组
Console.WriteLine(array[size]);
size++;
}
}
}
}
题目是按冒泡法排列所给数组,刚学C#的小白,不理解要怎么解决,麻烦大家帮忙看看
for(int j=0; i<array.Length-1-i;j++)
中间的哪个写成i了啊
for(int j=0; j<array.Length-1-i;j++)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace F3
{
class Program
{
static void Main(string[] args)
{
int[] array = { 1, 2, 6, 9, 4, 7, 13, 12, 5, 3, 8, 10, 11 };
int temp = 0;
for (int i = 0; i <= array.Length - 1; i++)
{
for (int j = 0; j < array.Length - 1 - i; j++)
{
if (array[j] > array[j + 1])
{
temp = array[j + 1];
array[j + 1] = array[j];
array[j] = temp;
}
}
}
int size = 0;
while (size < array.Length)
{ //输出排序后的数组
Console.WriteLine(array[size]);
size++;
}
}
}
}