1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include<iostream>
using namespace std;
int swap(int[], int, int);
int main(){
int slot[10] = { 100.10, 334.60, 290.80, 410.70, 600.00, 732.90, 870.92, 100.70, 590.89, 979.00 };
int n = 10, i;
int lower, upper, sortflag, sml, scan;
lower = 0;
upper = n - 1;
sortflag = 1;
while ((lower < upper) && (sortflag == 1)){
sml = lower;
sortflag = 0;
scan = lower + 1;
while (scan <= upper - lower){
if (slot[scan]>slot[scan + 1]){
swap(slot, scan, scan + 1);
sortflag = 1;
if (slot[scan] < slot[sml])sml = scan;
}//IF
scan++;
}//WHILE
swap(slot, lower, sml);
upper = upper - 1;
lower = lower + 1;
}//WHILE
cout << "ALEXANDRA'S NETPAY SORT:" << endl;
for (i = 0; i < n; i++)cout << slot[i] << "";
cout << endl;
return 0;
}//MAIN
int swap(int slot[], int i, int j){
int temp;
temp = slot[i];
slot[i] = slot[j];
slot[j] = temp;
return 0;
system("pause");
}//SWAP
|