Я пытаюсь найти второе по величине число в массиве. Почему этот код не работает?Сравните элементы NSMutableArray, чтобы найти второй по величине из списка
NSMutableArray *array1=[[NSMutableArray alloc]initWithObjects:@5,@25,@48,@2,@52,@53, nil];
id temp,larg2;int k=0;
while(k<2)
{
for(int j=0;j<5-k;j++)
{
if([array1 objectAtIndex:j]>[array1 objectAtIndex:j+1])
{
temp=[array1 objectAtIndex:j];
[array1 replaceObjectAtIndex:j withObject:[array1 objectAtIndex:j+1]];
[array1 replaceObjectAtIndex:j+1 withObject:temp];
if(k==1 && j==3). //this statement is not running??
{ larg2=temp;
NSLog(@"The answer is %@",larg2);
}
}
}
k++;
}
NSLog(@"The value of Second Largest Element is %@",larg2);
}
Как найти второй по величине элемент?
Не удалось найти второй по величине элемент ???? –