0

What's the best way to swap two arrays? Would it be better to copy each position into a new array and then assign the array a new name? Or would it be better to use pointers? What would the algorithm be if I were to use pointers or a dynamically allocated array? Thanks!

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by dougy83
0

Just swap the pointers, as long as nothing else is referencing any elements in the arrays. If there are other references/pointers pointing into the array then do something else - like the temporary array thing (it'll be a bit trickier if the arrays are different sizes).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.