Trying to get Random Array into bubble sort

I am trying to get my Array to work with bubble sort. I have the Array to pick 10 random numbers from 1 - 100. It prints the results, how ever when I go to add "numberArray" to bubble sort I get an error. The code I have is below any help would be great. It's probably something really stupid.


#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
srand (time (NULL));

const unsigned int sizeOfArray = 10;
int numberArray [sizeOfArray];

for (int i = 0; i < sizeOfArray; i++)
{
numberArray [i] = rand() % 100;
cout << numberArray [i] << endl;
}

int myArray [] = numberArray [] ;
int swapHolder = -1;

for (int index = 0; index <10; index++)
{
if (myArray [index] > myArray [index + 1])
{
swapHolder = myArray [index + 1];
myArray [index + 1] = myArray [index];
myArray [index] = swapHolder;
}
}

for (int index = 0; index < 10; index++)
{
cout << myArray [index] << ", ";
}

cout << endl;



}



You can't use the assignment operator= to "copy" an array you will need to copy the array element by element, or you could just sort the original array.



Topic archived. No new replies allowed.