I have a bit a of a problem. I'm trying to sort an array with objects in it. The objects are bottles with names, prices and types. The user makes a choice, which bottle he/she want's to add to the array.
For the assignment we have to use bubble sort. I've made it work, except it only sorts the price. The entire object doesn't switch place just the price itself. So if Coca-Cola's original price was 13 in list, after bubble sort it's 10. So the only thing that changes or gets sorted is the price and not the entire object, if that makes any sense.
public void sort_sodas()
{
int max = sodas.Length - 1;
for (int i = 0; i < max; i++)
{
int nrLeft = max - i;
for (int j = 0; j < nrLeft; j++)
{
if (sodas[j+1] == null)
{
break;
}
else if (sodas[j].Price > sodas[j+1].Price)
{
int temp = sodas[j].Price;
sodas[j].Price = sodas[j + 1].Price;
sodas[j + 1].Price = temp;
}
}
}
Below an image of before and after bubble sort:

var temp = sodas[j]; sodas[j] = ...and so onPrice. What type of objects are in thesodas? Can you swap whole objects instead?