#include<iostream>
using std::cout;
using std::endl;
template<class T>class Test
{
//冒泡排序
public :static void BubbleSort(T a[], int n)
{
int i, j;
T temp;
bool flag=false;
for(i=n-1;i>=0;i--)
{
flag=false;
for(j=0;j<i;j++)
{
if (a[j + 1]<a[j])
{
temp=a[j+1]; a[j+1]=a[j]; a[j]=temp;
flag=true;
}
}
if(flag==false) break;
}
} //end BubbleSort
}; //end Test
int main()
{
int i;
int a[5]={23,45,8,0,9};
Test<int>::BubbleSort(a,5);
for(i=0;i<5;i++)std::cout<<a[i]<<std::endl;
system ("pause");
return 0;
using std::cout;
using std::endl;
template<class T>class Test
{
//冒泡排序
public :static void BubbleSort(T a[], int n)
{
int i, j;
T temp;
bool flag=false;
for(i=n-1;i>=0;i--)
{
flag=false;
for(j=0;j<i;j++)
{
if (a[j + 1]<a[j])
{
temp=a[j+1]; a[j+1]=a[j]; a[j]=temp;
flag=true;
}
}
if(flag==false) break;
}
} //end BubbleSort
}; //end Test
int main()
{
int i;
int a[5]={23,45,8,0,9};
Test<int>::BubbleSort(a,5);
for(i=0;i<5;i++)std::cout<<a[i]<<std::endl;
system ("pause");
return 0;
}
代码是完全可以通过, 不用所谓接口,但是到了C#中,是无法通过的,提示: if (a[j + 1]<a[j]) 这一句有问题。。。。。
这是为什么??
一个能通过。一个不能通过