Let's say you have a bubble sort like this
Now, suppose that your "data" isn't a member within a simple structure (not shown) where it can easily get called, but rather it's the result of another calculation (like the area of a shape or something) within a separate function that gets looped through for as many shapes as you have when called. This function calculates the area on the fly (only when the function is called) and the values that are used for calculating the area are stored, but that's it.
How would you go about modifying this bubble sort (or would you use a completely different kind of bubble sort methodology?) so that you could arrange all the areas of as many shapes as you have in increasing (or decreasing, doesn't really matter) order? If you had to create another function that's perfectly acceptable.
I'm just wondering about this since I'm looking over all the different kinds of sorting algorithms and the different examples out there and I wanted to implement a bubble sort in mine...but as the scenario is described above...mine varies in terms of functions used and the way you go about getting "data".
Any insight is appreciated! Thanks !!
Now, suppose that your "data" isn't a member within a simple structure (not shown) where it can easily get called, but rather it's the result of another calculation (like the area of a shape or something) within a separate function that gets looped through for as many shapes as you have when called. This function calculates the area on the fly (only when the function is called) and the values that are used for calculating the area are stored, but that's it.
How would you go about modifying this bubble sort (or would you use a completely different kind of bubble sort methodology?) so that you could arrange all the areas of as many shapes as you have in increasing (or decreasing, doesn't really matter) order? If you had to create another function that's perfectly acceptable.
I'm just wondering about this since I'm looking over all the different kinds of sorting algorithms and the different examples out there and I wanted to implement a bubble sort in mine...but as the scenario is described above...mine varies in terms of functions used and the way you go about getting "data".
Any insight is appreciated! Thanks !!