#include <iostream>
#include <cstdlib>
using namespace std;
void Quick_sort(int M[], int first, int last)
{
int temp;
int i = first;
int j = last;
int MID = M[(first + last) / 2];
if (first >= last)
{
return;
}
do
{
cout << M[(first + last) / 2] << "\t" << MID << endl;
while (M[i] < M[(first + last) /2])
++i;
while (M[j] > M[(first + last) / 2])
--j;
if (i <= j)
{
temp = M[i];
M[i] = M[j];
M[j] = temp;
++i; --j;
}
} while (i <= j);
Quick_sort(M, first, j);
Quick_sort(M, i, last);
return;
//if (-1)
//{
//in:
// for (int l = 0; l < 3000; ++l)
// cout << M[l] << endl;
// return;
//}
}
int main()
{
int M[200];
srand(time(NULL));
for (int i = 0; i < 200; ++i)
{
M[i] = 1 + rand() % 499;
}
Quick_sort(M, 0, 199);
/*for (int i = 0; i < 200; ++i)
{
if (M[i] < M[i - 1])
cout << "loi" << endl;
else
cout << "ngon" << endl;
}*/
system("pause");
return 0;
}
Kết quả
tại sao em cùng xuất giá trị int MID = M[(first + last) / 2]; lại khác với giá tri của M[(first + last) / 2] ạ
mong mọi người giải thích giúp


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?