回覆列表
-
1 # 婦產神經病科老王主任
-
2 # 量子糾纏速度之謎
bool min2(int *result, int *array, int num)
{
int i, min;
if(num<=1)
return false;
min = array[0];
for(i=1; i<num; i++)
{
if(array[i]!=min)
break;
}
if(i==num)
return false;
*result = array[i];
if(*result<min)
{
*result = min;
min = array[i];
}
i++;
for(; i<num; i++)
{
if(array[i]==min)
continue;
if(array[i]>=*result)
continue;
if(array[i]<min)
{
*result = min;
min = array[i];
continue;
}
*result = array[i];
}
return true;
}
int* last2nd( int const * const arr, int num){
int min = arr[0];
int *res = nullptr;
for (int i = 1; i < num; ++i){
if(min == arr[i]){
continue;
}
if(min>arr[i]){
if(!res) res = new int;
*res = min;
min = arr[i];
}else if(!res||*res > arr[i]){
if(!res) res = new int;
*res = arr[i];
}
}
return res;
}