I 've gone to several companies for the last few days and found that there are all sorts. So I want to sort them all today, and I have called them in vs6.0.
This evening I summarized two orders.
1) Select sorting: place the maximum or minimum value on the top of each round
2) Bubble Sorting: Find the maximum or minimum sink to the bottom of each round
Select sortCode:
Void selectionsort (INT arr [], int N) // select sorting
{
Int smallindex;
Int pass, J;
Int temp;
For (pass = 0; pass <n-1; pass ++)
{
Smallindex = pass;
For (j = pass + 1; j <n; j ++)
If (ARR [J] <arr [smallindex])
Smallindex = J;
If (smallindex! = Pass)
{
Temp = arr [pass];
Arr [pass] = arr [smallindex];
Arr [smallindex] = temp;
}
}
}
Bubble Sorting code:
Void bubblesort (INT arr [], int N) // Bubble Sorting
{
Int bigindex;
Int pass, J;
Int temp;
For (pass = n-1; pass> 0; pass --)
{
Bigindex = pass;
For (j = 0; j <= pass; j ++)
{
If (ARR [J]> arr [J + 1])
{
Temp = arr [J];
Arr [J] = arr [J + 1];
Arr [J + 1] = temp;
}
}
}
}
Test code:
Void main ()
{
Int arr [15];
Int I;
Cout <"original array" <Endl;
For (I = 0; I <15; I ++)
{
Arr [I] = rand ();
Cout <arr [I] <"";
}
Cout <Endl;
// Selectionsort (ARR, 15 );
Bubblesort (ARR, 15 );
Cout <"sorted array" <Endl;
For (I = 0; I <15; I ++)
Cout <arr [I] <"";
Cout <Endl;
}
The next few orders will be processed tomorrow. Take a rest first, and O (∩) O ~