Member Avatar for lianaconda

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!

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.