C++ Storing Array in Separate File

Viewed 438

I am working on a c++ program in which I have to pass an array to multiple sorting functions and compare the running times of the functions. For example, I have an array with 100 elements containing random numbers from 1 to 10. I have a bubble sort, merge sort, and quick sort function, and I have to pass the array to each function. However when I pass the array, the first sorting function changes the original array so that when it is passed to the next function it is already sorted. This is expected, but I was wondering how I would store this array in a separate file, perhaps a header file, to keep the original array unsorted for each function call.

Here is a layout of my code:

#include <iostream>
using namespace std;

//void bubblesort, mergesort, quicksort function prototypes

int main()
{
    int a[100];
    for (int i = 0; i < 100; i++)
        a[i] = rand() % 10 + 1;
    bubblesort(a);
    mergesort(a);
    quicksort(a);
    return 0;
}

//void bubblesort, mergesort, quicksort function definitions

This code is obviously just a layout and the sorting functions aren't relevant for this question other than the fact that a call to a sorting function changes the original array. Thanks for your help.

3 Answers
Related