#import <Foundation/Foundation.h>
#import "maopaoSeq.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
maopaoSeq *a = [maopaoSeq new];
NSLog(@"请输入十个数");
for (int i=0; i<10; i++) {
scanf("%d",&(a->_arr[i]));
}
for (int i=0; i<10; i++) {
printf("%d ",(a->_arr[i]));
}
printf("\n");
// printf("\n");
// a -> _arr = {8,4,2,7,9,1,3,6,12,5};
[a maopaoSeq];
}
return 0;
}
#import <Foundation/Foundation.h>
@interface maopaoSeq : NSObject
{
@public
// int _a;
int _arr[10];
}
-(void)maopaoSeq;
@end
#import "maopaoSeq.h"
@implementation maopaoSeq
-(void)maopaoSeq{
int temp = 0;
for (int i=0 ; i<10; i++) {
for (int j=0; j<10-i; j++) {
if (_arr[j]>_arr[j+1]) {
temp = _arr[j];
_arr[j] = _arr[j+1];
_arr[j+1] = temp;
}
}
}
for (int i=0; i<10; i++) {
NSLog(@"%d",_arr[i]);
}
}
@end
|
|