I have this bubblesort loop
// bubblesort algorithm to find min & max values of array
for (int pass=1; pass<velg1_new_size; pass++)
// This next loop becomes shorter and shorter
for (int x=0; x < velg1_new_size-pass; x++)
if (velg1_new[x] > velg1_new[x+1])
// exchange elements
double temp_store = velg1_new[x]; velg1_new[x] = velg1_new[x+1]; velg1_new[x+1] = temp_store;
This loop goes through my array velg1_new. Unfortunately I have 6 arrays, velg1_new, velg2_new, accl1_new, accl2_new, dist1_new, dist2_new. Copying this algorithm 6 times do go through the 6 different arrays is obviously not an elegant or efficient way of doing this, my question is - how do I make the array names variable?
I was hoping I could do something like [arrayName][x] and then create and array of array names and just incriment arrayName. I was also thinking I could do something like a function call, and then just call the function so - bubbleSort(char x); and then replace [arrayName] with char? I'm losing myself now, I hope I'm making sense.
I am new to C++ so some help here would be fantastic.