为什么我这段代码可以运行,结果却不对呢
#include<iostream>using namespace std;
template <typename T>
void mySwap(T a,T b)
{
T temp = a;
a = b;
b = temp;
}
void sort(int *a, unsigned len, bool bigger=true )
{
for(int i=1;i<len;i++)
for (int i = 1; i < len; i++)
{
bool bcase = bigger ? a[i] > a[i - 1]:a[i] < a[i - 1];
if (bcase) mySwap(a[i],a[i-1]);
}
}
int main()
{
int a[5]{ 1,8,3,4,5 };
sort(a, 5);
for (auto x : a)std::cout << x << std::endl;
system("pause");
return 0;
}
有么有人知道,能告诉我吗非常感谢