//排序算法(冒泡排序)
- (void)sortingAlgorithmMethod {
int arr[] = {2,6,3,1,7,10,3,5,8,34,56,0,1,4,9,17,13,15,12,33};
int cnt = 20;
int count = 0;
for (int i=1; i<cnt; i++) {
for (int j=0; j<cnt-i; j++) {
if(arr[j]>arr[j+1]) {
//*******************
//交换操作(辅助字段名temp)
int temp = arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
//*******************
}
count++;
}
}
}
冒泡排序算法
于 2020-10-30 17:30:48 首次发布