Treating handles as C pointers may help with your understanding.
In C given 2 pointers, swapping is simply changing what they points to.
But if you indeed want the contents of the two handles to be swapped:
- Clone() doesn't help because you will eventually changing the pointer again
- Instead you should fill both ArrayList with contents of the other cell by cell
Bet there's better algorithm but this should go as straight as it shows.
PHP Code:
void SwapADTArray(ArrayList a1, ArrayList a2)
{
int blocksize = a1.BlockSize;
if (blocksize != a2.BlockSize)
{
ThrowError("");
}
int len1, len2;
len1 = a1.Length;
len2 = a2.Length;
ArrayList temp = a2.Clone(); // save a2 first
a2.Resize(len1);
for (int i = 0; i < len1; ++i) // copy a1 contents to a2
{
for (int j = 0; j < blocksize; ++j)
{
a2.Set(i, a1.Get(i, j), j);
}
}
a1.Resize(len2);
for (int i = 0; i < len2; ++i) // copy a2 contents to a1
{
for (int j = 0; j < blocksize; ++j)
{
a1.Set(i, temp.Get(i, j), j);
}
}
delete temp;
}