-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.m
More file actions
31 lines (29 loc) · 739 Bytes
/
Copy pathBubbleSort.m
File metadata and controls
31 lines (29 loc) · 739 Bytes
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
//
// BubbleSort.m
// BaseAlgorithm
//
// Created by CC on 2020/4/21.
// Copyright © 2020 kayak. All rights reserved.
//
#import "BubbleSort.h"
#import "TestUtil.h"
@implementation BubbleSort
-(void)test{
// int *arr = [TestUtil createRandomNumbers:20];
int arr[] = {1,3,11,3,5,6,7,33,16,75,14,88,91,34,65,65,23,21,37,68};
[TestUtil printArray:arr length:20];
[self sort:arr length:20];
[TestUtil printArray:arr length:20];
}
-(void)sort:(int*)arr length:(int)length{
for(int i=0; i<length;i++) {
for (int j=i; j<length-1; j++) {
if(arr[j]>arr[1+j]){
int tmp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = tmp;
}
}
}
}
@end