How to find the values being swapped in two different arrays?
and not allowed to use the std library
{2, 3, 6}
{1, 4, 7}
will become
{1, 3, 7}
{2, 4, 6}
With 2 swaps, and the values being swapped are
1 & 2, 6 & 7
So far, I have gotten the swap and counter to work but I cannot seem to figure out how to find the individual values of the elements that are swapped, I can get only one value to show.
Can I get any hints on how to all grab the values? I am not allowed to use any additional libraries except for the input and output streams. Thanks ahead of time.
Your current program is not even outputting a value. Its outputting the index of the array. More specifically, its outputting the final index which was swapped, which happens to be 2.
Another solution is to make an array (maybe call it 'swapArray') the size of 6 (since that is the most amount of values that can be swapped). Fill up the array with the swapped values within the if-statement.
Then traverse through the array using a for-loop going up to 2*swapcount (as each swapcount means 2 values being swapped), and cout the values.
If you're able to use std::vector, I'd create a vector, and then push_back() the values that were swapped into the vector every time the swapValue gets called. Then have a for loop that calls on .size() and output the contents of that vector (the contents that got swapped).