#import <Foundation/Foundation.h>
void selectSort();
int main(int argc, const char * argv[]) {
@autoreleasepool {
int arr[6] = {3,1,8,6,4,2};
for (int i=0; i<5; i++) {
for (int j=0; j<5-i; j++) {
if (arr[j]>arr[j+1]) {
int temp;
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for (int i=0; i<6; i++) {
printf("%d\t",arr[i]);
}
printf("\n");
selectSort();
}
return 0;
}
// 选择排序
void selectSort(){
int arr[6] = {3,1,8,6,4,2};
for (int i=0; i<5; i++) {
for (int j=i+1; j<6; j++) {
if (arr[i]>arr[j]) {
int temp;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for (int i=0; i<6; i++) {
printf("%d\t",arr[i]);
}
printf("\n");
}
|
|