以下のコードを C から Obj-C に変換しています。C コード行は以下にコメントされ、 Obj-C に置き換えられていますが、結果に問題があり、並べ替えが正しく機能していません。助けてください
-(IBAction)clicked_insertsort:(id)sender{
NSMutableArray *iarray = [[NSMutableArray alloc]initWithArray:garr];
int n = [iarray count] ;
NSLog(@"%@",iarray);
int i,j,x;
for(i=1;i<=n-1;i++)
{
j=i;
//x=a[i];
x=[[iarray objectAtIndex:(NSUInteger)i]intValue];
//while(a[j-1]>x && j>0)
while (j>0 &&[[iarray objectAtIndex:(NSUInteger)j-1]intValue] >x)
{
//a[j]=a[j-1];
[iarray replaceObjectAtIndex: (j) withObject: [iarray objectAtIndex: (j-1)]];
j=j-1;
}
// a[j]=x;
[[iarray objectAtIndex:(NSUInteger)j]intValue] == x;
}
NSLog(@"%@",iarray);
}
ソート前
[Session started at 2012-09-12 02:13:43 +0300.]
2012-09-12 02:13:49.127 sort_alg[1748:207] (
43,
18,
15,
135,
37,
81,
157,
166,
117,
110
)
and after sort
2012-09-12 02:13:49.130 sort_alg[1748:207] (
43,
43,
43,
43,
135,
135,
135,
135,
157,
166
)