Hello everyone, I am familiar with a normal bubble sort when dealing with an array of number but I am unsure as how to implement a sort when I have an array that is filled with classes which hold multiple values.
I need to make a bubble sort that reaches into an array called Tree[100] which has in each storage location a class called Christmas Tree which have the values Species, Height, trunkDiameter, and costPerFoot. The sort will need to sort the different trees by species (which is a string) and then by costPerFoot (a double).
Regular bubble sort:
Any ideas?
I need to make a bubble sort that reaches into an array called Tree[100] which has in each storage location a class called Christmas Tree which have the values Species, Height, trunkDiameter, and costPerFoot. The sort will need to sort the different trees by species (which is a string) and then by costPerFoot (a double).
Regular bubble sort:
Code:
void bubblesort (int a[], int n) // n = SIZE; { bool sorted = false; for (int i = 0; i < n-1 && !sorted; i++) { sorted = true; for (int j = 0; j < (n-1-i); j++) { if (a[j] > a[j+1]) { swap (a[j], a[j+1]); sorted = false; } } } }
Comment