Indika Bandara wrote:
> #define MAX_NUM 5
>
> struct P
> {
>
> P(){};
> P(int i){_i = i; };
> int _i;
> };
>
> int Comp(const void* p1, const void* p2)
> {
> P* i1 = (P*)p1;
> P* i2 = (P*)p2;
> if(i1->_i>i2->_i)
> return 1;
> if(i1->_i<i2->_i)
> return -1;
>
> return 0;
> }
>
> int main(int argc, char** argv)
> {
> P** p = new P*[MAX_NUM];
> p[0] = new P(1);
> p[1] = new P(9);
> p[2] = new P(8);
> p[3] = new P(3);
> p[4] = new P(2);
> printf("before\n");
> for(int i=0; i<MAX_NUM; i++)
> printf("%d\n", p[i]->_i);
>
> qsort(p, MAX_NUM, sizeof(P*), Comp);
>
> printf("after\n");
> for(int i=0; i<MAX_NUM; i++)
> printf("%d\n", p[i]->_i);
>
>
> // leak
>
>
> }
>
>
> ===========================
> before
> 1
> 9
> 8
> 3
> 2
> after
> 1
> 9
> 8
> 3
> 2
> ===========================
>
some day you should decide whether you're going to write in C or C++
the mix is foolish