qq_33298527 于 2016.05.05 00:00 提问

#include
#include
using namespace std;
template
class A{
public:
void up(T aa, int size){
qsort(aa, size, sizeof(*aa), cmp);
for (int i = 0; i < size; i++) cout << aa[i] << endl;
}
int cmp(const void *a, const void *b){
if (
(T*)a > (T)b) return 1;
else return -1;
}
};
int main(){
A a;
int i[5] = { -1, 0, 6, 3, 0 };
a.up(i, 5);
system("pause");
}

4个回答

caozhy      2016.05.05 00:05

int cmp(const void *a, const void *b)

asd001110   2016.05.05 01:11

template
class A
{
public:
void up(T aa, int size)
{
//qsort(aa, size, sizeof(*aa), cmp);
for (int i = 0; i < size; i++)
cout << aa[i] << endl;
}
int cmp(const void a, const void *b)
{
if ((T
)a > (T)b) return 1;
else return -1;
}
};
int main()
{
A a;
int i[5] = { -1, 0, 6, 3, 0 };
a.up(i, 5);
system("pause");
return 0;
}

asd001110   2016.05.05 01:17

template
class A
{
public:
void up(T aa, int size)
{
//qsort(aa, size, sizeof(*aa), cmp);
for (int i = 0; i < size; i++)
cout << aa[i] << endl;
}
int cmp(const void a, const void *b)
{
if ((T
)a > (T)b) return 1;
else return -1;
}
};
int main()
{
A a;
int i[5] = { -1, 0, 6, 3, 0 };
a.up(i, 5);
system("pause");
return 0;
}

``````
``````
asd001110   2016.05.05 01:20