//冒泡排序算法
#import <Foundation/Foundation.h>
void BubbleSort(int *arr, int n)
{
int temp;
for(int i = 1; i < n; i++)
{
for(int j = n - 1; j >= i; j--)
{
if (arr[j] < arr[j - 1]) {
temp = arr[j - 1];
arr[j - 1] = arr[j];
arr[j] = temp;
}
}
}
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int arr[] = {10,5,4,3,8};
BubbleSort(arr, 5);
for(int i = 0; i < 5; i++)
{
NSLog(@"%i",arr[i]);
}
[pool drain];
return 0;
}
浙公网安备 33010602011771号