Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Visual Logic -Bubble Sort


  • Please log in to reply

#1
DevonDaDude

DevonDaDude

    New Member

  • Member
  • Pip
  • 5 posts
Ok, I'm trying to learn bubble sort, but how do you declare it? I'm unfamiliar, I'm reading this book and I can't seem to get it.. Can someone show me an example in visual logic? Thank You.
  • 0

Advertisements


#2
mpascal

mpascal

    Math Nerd

  • Retired Staff
  • 3,644 posts
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:
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?
  • 0

#3
DevonDaDude

DevonDaDude

    New Member

  • Topic Starter
  • Member
  • Pip
  • 5 posts
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.. :)
  • 0

#4
mpascal

mpascal

    Math Nerd

  • Retired Staff
  • 3,644 posts
Sounds good, I'll take a look at it and see if I can see what's wrong :)
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP