DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   arranging 5 numbers from lowest to highest PLS HELP (http://www.daniweb.com/forums/thread201994.html)

stevenaseron Jul 6th, 2009 10:57 am
arranging 5 numbers from lowest to highest PLS HELP
 
um ive been asked by my prof to do a program that could possibly arrange 5numbers from lowest to highest..but im kinda new with programing can sumone pls help me THNXX

trshaaa Jul 6th, 2009 11:12 am
Re: arranging 5 numbers from lowest to highest PLS HELP
 
I which language...?I can pots you one solution in c if you want....

stevenaseron Jul 6th, 2009 11:16 am
Re: arranging 5 numbers from lowest to highest PLS HELP
 
jbasic...thnxx

wildgoose Jul 6th, 2009 11:18 am
Re: arranging 5 numbers from lowest to highest PLS HELP
 
There are many sort algorithms in existance. The simplest but slowest is you have all your values in an array and you know the count of the array.


swap = true
while swap is true
  swap = false
  for index = 0 to cnt-1 step 1
      if ary[index] > ary[index+1] then
            tmp = ary[index]
            ary[index]=ary[index+1]
            ary[index+1] = ary[index]
            swap = true
      endif
    endfor
endwhile

This one is very inefficient but will do the job. In essence the outer loop will loop forever until no swaps occur in the inner loop. This is know as a bubble sort as the numbers bubble along into their correct positions.

I strongly recommend you read up on sorting. Knuth has a great book on the subject containg pseudo code. His books are well worth having a prominent place in your bookcase.


[45][ 3][21][11][2]
  3  45  21  11  2
  3  21  45  11  2
  3  21  11  45  2
  3  21  11  45  2
          next outer loop without the little steps
  3  11  21  2  45 
  3  11  2  21  45
  3    2  11  21  45
  2    3  11  21  45

stevenaseron Jul 6th, 2009 11:21 am
Re: arranging 5 numbers from lowest to highest PLS HELP
 
o ok..ow and thnxx alot i really needed these codes

stevenaseron Jul 6th, 2009 11:42 am
Re: arranging 5 numbers from lowest to highest PLS HELP
 
dude can u help me do this in a flowchart ? cuz im told to do it that way PLS HELP ME this really means alot to me THNXX


All times are GMT -4. The time now is 9:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC