Hi
Helios,
Are you sure the rest of the code in the loop does what you think it does? What it really does is not swap two numbers. It's swapping two vectors; two rows, if you will. |
Can't I use iter_swap() function to swap numbers?
Hi
lastchance,
I think it would be easier to advise if you gave us VERBATIM the bit of your assignment BEFORE what you have quoted: we are only getting a very confused story and it is unclear what you are being asked. |
Sorry for inconvenience. I was given a task to generate two random numbers between 3 to 9.
For example: first random number = 5 and second random number = 9.
Then, I need to find the position of these random number for each row vector as follow:
{ 9, 8, 7, 6, 5, 4, 3, 2, 1 } --> first random number = position 5, second random number = position 1
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 } --> first random number = position 5, second random number = position 9
{ 5, 4, 3, 2, 1, 9, 8, 7, 6 } --> first random number = position 1, second random number = position 6.
Then, swap these random numbers for each row
{ 9, 8, 7, 6, 5, 4, 3, 2, 1 } --> { 5, 8, 7, 6, 9, 4, 3, 2, 1 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 } --> { 1, 2, 3, 4, 9, 6, 7, 8, 5 }
{ 5, 4, 3, 2, 1, 9, 8, 7, 6 } --> { 9, 4, 3, 2, 1, 5, 8, 7, 6 }