In front we learned the for Loop, where we use the For loop we learned earlier to implement a bubbling sort operation. Typically, a bubble sort is a small-to-large sort.
Here is the core source code that I implemented:
int[] array_01=New int[Ten];
Randomrandom_01=New Random();
// start to create random series
Console.WriteLine(" Start output Random series:" );
for(inti=0; i<array_01.length;i++)
{
array_01[i]=random_01.Next(1,101);
}
// output a random sequence
for(inti=0; i<array_01.length;i++)
{
Console.Write(array_01[i]+"\ T");
}
// start bubble sort
//For example:Ten,9,8,7,6,5,4,3,2,1order from left to right, minimum number on left, maximum number on right
The // outer Loop represents the index of the number that is ready to be determined
for(inti=0; i<=array_01.length-1; i++)
{
The // inner loop represents: Determines the number of times an interchange is required
for(intj=1; j<=array_01.length-1-i;j++)
{
// compare to determine if you want to swap
if(Array_01[i]>array_01[i+j])
{
inttemp;
Temp=array_01[i];
Array_01[i]=array_01[i+j];
array_01[i+j]=temp;
}
}
}
Console.WriteLine("The result of the comparison is:" );
Results of//output comparison
for(inti=0; i<=array_01.length-1; i++)
{
Console.Write(array_01[i]+"\ T");
}
This article is from the "Smile" blog, please be sure to keep this source http://yiyiweixiao.blog.51cto.com/2476874/1970626
19. Bubble sort operation in C #