Results 1 to 7 of 7

Thread: wickedly easy sorting challenge

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268

    wickedly easy sorting challenge

    hello, my brain is mush this mornin, and ive forgotten everything i know about sorting, so maybe you guys can help

    i have an array of things, lets say x, each x has an O2 and a thickness. I want to sort the x's in order of their O2 and.......... uh nevermind the rest, hehe. i'll get onto that later.

    the array of x can vary in length from 1 to 20, yes, that's right it must sort a max of 20

    and ideas?
    thanks for your time
    Ang

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    dont worry bout that, i found on on google

    thanks all the same
    Ang

  3. #3
    wossname
    Guest
    I sincerely hope you are not planning to use a variant of the dreadful bubble sort!

    PS, whats an O2?

  4. #4
    wossname
    Guest
    This has been bugging me for a few days now...Just what algorithm are you using?

    I heartily recommend the Counting sort algorithm, for such a small number of items.

  5. #5
    Devioux
    Guest
    :P

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    here is my sorting procedure, its a bit hairy, hope u can follow it


    For i = 0 To (FinalBagCount - 1)
    Biggest = i

    For j = (i + 1) To FinalBagCount - 1
    If (BagArray(Biggest).GetO2 < BagArray(j).GetO2) Then Biggest = j
    Next j

    tempb.CopyBag Bag:=BagArray(i)
    tempf.CopyFilm Film:=FilmArray(i)
    BagArray(i).CopyBag Bag:=BagArray(Biggest)
    FilmArray(i).CopyFilm Film:=FilmArray(Biggest)
    BagArray(Biggest).CopyBag Bag:=tempb
    FilmArray(Biggest).CopyFilm Film:=tempf
    Next i

    puts them in descending order........... what i really want to do is sort it by closest to Produce.Optimums, what i had was:

    For i = 0 To (FinalBagCount - 1)
    Biggest = i

    For j = (i + 1) To FinalBagCount - 1
    BagDiff1 = Absolute(BagArray(Biggest).GetO2 - Produce.GetOptO2)
    BagDiff2 = Absolute(BagArray(j).GetO2 - Produce.GetOptO2)
    If (BagDiff1 > BagDiff2) Then Biggest = j
    Next j

    tempb.CopyBag Bag:=BagArray(i)
    tempf.CopyFilm Film:=FilmArray(i)
    BagArray(i).CopyBag Bag:=BagArray(Biggest)
    FilmArray(i).CopyFilm Film:=FilmArray(Biggest)
    BagArray(Biggest).CopyBag Bag:=tempb
    FilmArray(Biggest).CopyFilm Film:=tempf
    Next i

    only this didnt sort them correctly. can anyone tell me why?

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    oh i figured out why it didnt work. I was using integers when it should have been singles. haha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width