i have an array of 9 numbers and my functions in my number class are used to reorder the 9 numbers in the array without any duplicate of numbers and then to list the number of times the rand() function was called. I now need to generate ten lists of the numbers and store them into a vector. here is the code:
class numbers{
private:
int indexCount;
public:
void swap (int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void printArray (int arr[], int n)
{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << "random calls: " << indexCount <<endl;
}
void randomize (int arr[], int n)
{
indexCount=0;
srand (time(NULL));
for (int i = n - 1; i > 0; i--)
{
int j = rand() % (i + 1);
indexCount++;
swap(&arr[i], &arr[j]);
}
}
};
class numbersVector{
private:
vector <int>numberList;
public:
numbers num;
void storeInVector(int arr[], int n){
for (int i=0; i <10; i++){
num.randomize(arr,n);
num.printArray(arr,n);
numberList.push_back(arr[i]);
}
cout <<endl <<endl;
}
};
int main(){
numbers numbers;
numbersVector nv;
int arr[] = {1, 2, 3, 4, 5, 6, 0, 0, 0};
int n = sizeof(arr) / sizeof(arr[0]);
//numbers.randomize(arr, n);
// numbers.printArray(arr, n);
nv.storeInVector(arr,n);
return 0;
}
in my second class i loop over my functions in the first class to generate 10 list, i am now stuck on storing the randomised list into a vector. My problem is, i can only store numbers from each list into the vector but i would like to store the 10 lists inside the vector. EG
for (int i = 0; i <numberList.size(); i++)
{
cout <<numberList[i] <<endl;
}
i would want my output to be:
123456000 random calls: 8
02103654 random calls:8
and so on 10 times.
EDITING POST TO BE MORE CLEAR: so i have an array
arr[] = {1,2,3,4,5,6,0,0,0}
after my randomise function i get a output like this {2,1,0,0,6,0,4,3,5} i then create a loop to run my randomise function 10 times. ie 1)1,0,0,0,2,5,4,3,6 2)6,0,5,0,4,0,3,2,1 3)5,1,0,0,2,0,3,6,4 .... 10)2,1,0,0,6,0,4,3,5
i would then like to store each generated list into a vector IE
vector <int> numlist;
numList[1] = {1,0,0,0,2,5,4,3,6}
numList[2] = {6,0,5,0,4,0,3,2,1}
and so on