Hello,
Does anyone know of a way of making a high score style score ranking system? There are 'A is Greater than B' events but how would you code 'A is greater than B but not as great as C or D' (making A third in the list). Is there a way of sorting values without having to input events for every ordering possibility?
Any ideas would be very much appreciated.
Basically, I want to order counter values from top to bottom in a list in order of size. Is there any way that you can order these numbers without coding events for every possibility? Any ideas?
I'm going to repeat myself and say, you need to give more information. the more information you give the better answer you will receive.
Read my post again. I gave you several ideas. just in case you aren't aware of handy tools like google, and wikipedia, here is a place for you to start on my last and most useful idea on bubble sorting values. http://en.wikipedia.org/wiki/Bubble_sort
Cecilizer, Thanks very much for the bubble sorting idea and link- it's really logical. It flew straight over my head when I read your first post, maths is like a brick wall to me. sorry for making you repeat yourself. Happy Halloween!
just in case i can clarify how a bubble sort works.
a bubble sort works by taking a list of what is assumed to be unsorted values. take for example the numbers 1 through 5 jumbled up.
2 5 1 3 4
in order to sort them from smallest to largest you loop through the list from left to right, swapping the values positions if the left value is greater than the right. you make multiple passes through the list until all values are sorted. you use the same approach to sort from largest to smallest, only you check to see if the left value is less than the right before swapping.
in the given example you loop through the entire list making the following swaps.
first pass on the list is as follows.
[2 5] 1 3 4 = no swap. 2 is less than 5. list remains the same.
2 [5 1] 3 4 = swap. 5 is larger than 1. list is now 2 1 5 3 4.
2 1 [5 3] 4 = swap. 5 is larger than 3. list is now 2 1 3 5 4.
2 1 3 [5 4] = swap. 5 is larger than 4. list is now 2 1 3 4 5.
it is posited that on each pass, the value in the position equal to the length of the list minus the number of passes previously performed will be the largest value in that pass. in the first pass 5 is the largest number in the list and is now in the last position of the list (position 5) which is 5 - 0.
second pass on the list is as follows.
[2 1] 3 4 5 = swap. 2 is larger than 1. list is now 1 2 3 4 5.
1 [2 3] 4 5 = no swap. 2 is less than 3. list remains the same.
1 2 [3 4] 5 = no swap. 3 is less than 4. list remains the same.
we only made 3 comparisons this pass as opposed to the 4 comparisons we made during the previous pass. this is because at this point we already know that the largest number is in the next spot. so we stop. we now also know that the second largest value is in the second to last position, and the algorithm takes this into account for the next pass. even further we notice that the list is already sorted, however, our algorithm does not. so we begin the next pass.
third pass on the list is as follows.
[1 2] 3 4 5 = no swap. 1 is less than 2. list remains the same.
1 [2 3] 4 5 = no swap. 2 is less than 3. list remains the same.
we know from the previous passes that the next spots are already filled with the properly sorted values, so we stop. we also notice that no swaps were made during this pass. we can posit from this information that because the next positions are already sorted, and that no swaps were made, that the rest of the list must also be sorted, and there is no need to perform the last pass.
further notes: the reason we don't loop through the entire list comparing ALL values each pass is because we KNOW that the last position in the previous pass is the largest number for that pass. this allows us to do one less comparison for each successive pass thereby increasing our algorithms performance. Also, if during any given pass, no swaps are made, we can stop the algorithm because we know that the list is fully sorted. this also increases performance when a list is already partially sorted.
this animated image on the wiki shows the same process with a larger set of jumbled numbers. 1 through 8. please note that it can be any set of numbers, and they don't have to be sequential. the set 100 4 24 99 1 3 505 would work just as well.
interesting to note that the image doesn't make use of the "if no swaps are made, sorting is finished" posit. waste of processing cycles doing unnecessary comparisons. shame on them.
I had never heard of the Bubble Sort method until I read this thread and since Lobot, you find maths was like a brick wall I decided I would code it out for ya.
The zip file contains the mfa (fully commented) and an exe build. Hope you find it useful!
And please ignore the bubbles.... I needed to fill in space.
Ah, you guys are great. Chris, your program makes a lot of sense (I understand the comments and theory at least)-like a ladder for maths walls. More fancy than I'll be needing but I will definitely be having a dig around in the source file to try and get my head around the equations. Thanks very much.