Visual Logic -Bubble Sort
Started by
DevonDaDude
, Oct 08 2009 01:31 AM
#1
Posted 08 October 2009 - 01:31 AM
#2
Posted 08 October 2009 - 02:30 PM
Hi DevonDaDude,
I don't know visual logic, but I can try my best to explain what's going on. Basically you will need an array of numbers (or whatever you want to sort) and a temp variable. I'll try an example. Consider the following list of numbers:
First off, you want a loop that will compare two numbers in sequence, and determine which is bigger or smaller. We'll arrange these smallest to largest. So on the first set, this is what would happen:
You are then left with something like this:
As you can see, we will have to do this with each pair ([1] and [2], [2] and [3], etc.) After the first pass, you will be left with something like this.
As you can see, we are not quite done yet. In this example, the numbers are fairly sorted at the beginning; however if they weren't, you would have to pass through a few more times. As a general rule, you have to pass through (Number of Objects) - 1 times to get it all sorted.
Does this make sense?
I don't know visual logic, but I can try my best to explain what's going on. Basically you will need an array of numbers (or whatever you want to sort) and a temp variable. I'll try an example. Consider the following list of numbers:
2 1 4 5 3 6 Array [0] [1] [2] [3] [4] [5]
First off, you want a loop that will compare two numbers in sequence, and determine which is bigger or smaller. We'll arrange these smallest to largest. So on the first set, this is what would happen:
2 > 1? -> True Temp = Array[0] -> Put the number "2" in the temp variable Array[0] = Array[1] -> Set Array[0] (originally 2) equal to the number in Array[1] (1) Array[1] = Temp -> Put the number "2" into Array[1]
You are then left with something like this:
1 2 4 5 3 6 Array [0] [1] [2] [3] [4] [5]
As you can see, we will have to do this with each pair ([1] and [2], [2] and [3], etc.) After the first pass, you will be left with something like this.
1 2 4 3 5 6 Array [0] [1] [2] [3] [4] [5]
As you can see, we are not quite done yet. In this example, the numbers are fairly sorted at the beginning; however if they weren't, you would have to pass through a few more times. As a general rule, you have to pass through (Number of Objects) - 1 times to get it all sorted.
Does this make sense?
#3
Posted 13 October 2009 - 12:23 PM
I follow your example in visual logic and I'm still not getting the program to work. When I reach at home i'll post my pseudocode of visual logic, probably you or someone here can give me hints to what i'm doing wrong. Thank You, mpascal..
#4
Posted 13 October 2009 - 01:41 PM
Sounds good, I'll take a look at it and see if I can see what's wrong
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users