T
tienlx
Hi all,
I want to sort an array of struct _line:
....
typedef struct _line
{
int x1;
int x2;
} line;
bool comp(line l1,line l2)
{
if (l1.x1==l2.x1) return (l1.x2 < l2.x2);
return (l1.x1 < l2.x1);
}
line* R;
....
R = new line[k];
....
sort(&R[0],&R[k],comp);
....
delete[] R;
And when i printed out the array R, the result is wrong, but i run
well when i use vector<line>. And i don't know why sometimes the
program crashes when i use delete[] R; .Remove this line, it doesn't.
I use DevC++ 5, Win Vista.
Thanks for help,
tl
I want to sort an array of struct _line:
....
typedef struct _line
{
int x1;
int x2;
} line;
bool comp(line l1,line l2)
{
if (l1.x1==l2.x1) return (l1.x2 < l2.x2);
return (l1.x1 < l2.x1);
}
line* R;
....
R = new line[k];
....
sort(&R[0],&R[k],comp);
....
delete[] R;
And when i printed out the array R, the result is wrong, but i run
well when i use vector<line>. And i don't know why sometimes the
program crashes when i use delete[] R; .Remove this line, it doesn't.
I use DevC++ 5, Win Vista.
Thanks for help,
tl