class Sort
{
public void BubbleSort(int[] list)
{
int temp;
for (int i = 0; i < list.Length-1; i++)
{
//flag respresents this samsara whether changed flag value ,if not changed respresents
//un-sort region is sorted,do without sort again.
bool flag = true;
for (int j = 0; j < list.Length -1 - i; j++)
{
if (list[j] > list[j+1])
{
flag = false;
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
if (flag)
{
break;
}
}
}
}
{
public void BubbleSort(int[] list)
{
int temp;
for (int i = 0; i < list.Length-1; i++)
{
//flag respresents this samsara whether changed flag value ,if not changed respresents
//un-sort region is sorted,do without sort again.
bool flag = true;
for (int j = 0; j < list.Length -1 - i; j++)
{
if (list[j] > list[j+1])
{
flag = false;
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
if (flag)
{
break;
}
}
}
}
浙公网安备 33010602011771号