Because you cannot do this:
Code:
int size = 0;
cin >> size;
int iArray[size];
I had to dynamically allocate it like this:
Code:
int *dataint;
dataint = new int [size];
int *dataint2;
dataint2 = new int [size];
long int randomvalue = 0;
for (int i=0; i < size; i++)
{
randomvalue = ((rand()%(size-0)) + 0); //gives a random number between 0 and size
dataint[i] = dataint2[i] = randomvalue;
cout << randomvalue << endl;
}
....................
// Run sort algorithm here
dataint = dataint2; //this is where I want it to COPY dataint2's data over to
//dataint, but NOT just point to it... because then
//a) I can't use delete [] dataint2; because deleting dataint does that already.
//and
//b) the next time I try to reinintialize it, it is already sorted because dataint
//points to dataint2 at that point.
delete [] dataint;
delete [] dataint2;
So if size is 5; and it initializes dataint and dataint2 as this:
1
3
2
5
3
then it sorts it:
1
2
3
3
5
then "reinitializes" it:
1 (should be 1)
2 (should be 3)
3 (should be 2)
3 (should be 5)
5 (should be 3)
then "sorts" it, only its not changed because it is already sorted:
1
2
3
3
5
And if I use
*dataint = *dataint2;
and the beginning initialization was:
4
5
7
0
9
7
4
3
2
4
then it reinitializes as this:
4
2
3
4
4
4
5
7
7
9
And the second time:
4
3
4
4
4
4
5
7
7
9