J
Jinjun Xu
Hi,
I have an array and I want to adjust the size (remove some elements). I use
the following code. Can you help me to check whether it's correct.
////////////// start
int *p1 = new int[oldsize];
// ....
// set the values of p1
int *p2 = p1;
p1 = new int[newsize];
// copy some values from p2 to p1
for ( i = 0; i .... )
if (....) p1 = p2;
delete []p2;
////////////// end
Suppose I have an array, e.g., int *p1 = new int[10]; is there any easy way
to reset the length of p1? (e.g, p1 becomes int[20] and the first 10
elements keep the original value).
Thank you very much in advance for your help!
JJ
I have an array and I want to adjust the size (remove some elements). I use
the following code. Can you help me to check whether it's correct.
////////////// start
int *p1 = new int[oldsize];
// ....
// set the values of p1
int *p2 = p1;
p1 = new int[newsize];
// copy some values from p2 to p1
for ( i = 0; i .... )
if (....) p1 = p2;
delete []p2;
////////////// end
Suppose I have an array, e.g., int *p1 = new int[10]; is there any easy way
to reset the length of p1? (e.g, p1 becomes int[20] and the first 10
elements keep the original value).
Thank you very much in advance for your help!
JJ