I have an array of pointers on my class which I need to sort. Sorting is working correctly, Im just not sure, whether Im switching just reference on class, or the whole class...
My code is like:
ITEM *items = new ITEM[set.pathc];
...
bool change = true;
while( change )
{
change = false;
for( i = 0; i < set.pathc-1; i++ )
{
if( compare( items+i, items+i+1, set.order, set.order_asc ) )
{
ITEM temp;
temp = *(items+i);
items[i] = items[i+1];
items[i+1] = temp;
change = true;
}
}
}
So is my code switching just pointers (I mean adresses of where the object is allocated) or the whole objects (like copying all of the private variables, wouldn't it need "=" operator for this?) ?
I want to switch just pointers because I guess it would be much more faster, I tried it like this
ITEM *temp
temp = item+i;
item[i] = item+i+1;
item[i+1] = temp;
but it didnt work :-/ (I couldnt even compile the code)
thanks in advance for explaining :)