✔ 最佳答案
#include <iostream>
using namespace std;
int main()
{
const int max = 13;
int counti, countj, buffer = 0;
int low=0, high=max-1, middle;
int number[max] = {37,5,84,92,10,49,56,81,63,21,75,52,13};
cout << "排序前:";
for (counti = 0; counti < max; counti++)
cout << number[counti] << '\0';
///////////////////////////////
for (counti = 0; counti < max-1; counti++)
for (countj = counti; countj < max; countj++)
if (number[counti] > number[countj])
{
buffer = number[counti];
number[counti] = number[countj];
number[countj] = buffer;
}
cout << "\n排序後:";
for (counti = 0; counti < max; counti++)
cout << number[counti] << '\0';
cout<<endl;
do
{
if ((low + high) % 2 > 0.5)
{
middle = (low + high) / 2 + 1;
cout << "無中間值" << endl;
break;
}
else if((low + high) % 2 == 0)
{
middle = (low + high) / 2;
cout << "中間值為:" << number[middle];
cout<<endl;
break;
}
}while(low <= high);
system("pause") ;
return 0;
}
我是用二分搜尋法的概念去修改的
有問題可以補充喔~