Array sorting?
Posted: Thu May 23, 2013 6:29 pm
Hi all,
Im looking to sort my array if I remove an item, how is this best done?
Here is my awful code so far:
Logic:
If an item is 0 but the next array value is greater than 0(contains an item)
Move the value ahead back to the current value. Does this make sense? I just want to push up the array when an item is removed.
Im looking to sort my array if I remove an item, how is this best done?
Here is my awful code so far:
- Code: Select all
void sortInventory()
{
int i;
for(i=0;i<50;i++)
{
if(inventory[0][i]==0 && inventory[0][i+1]>0)
{
inventory[0][i+1]=inventory[0][i-1];
}
}
}
Logic:
If an item is 0 but the next array value is greater than 0(contains an item)
Move the value ahead back to the current value. Does this make sense? I just want to push up the array when an item is removed.