A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: anyone remember good ol' BUBBLE SORT?

  1. #1
    kay, here's the deal:
    i'm coding my second ever flash game (video poker), and in order to find out if the player has a Straight, I need to sort the values of the cards.
    the card values go from 1 (ace) to 13 (king), and are stored in 5 variables, called, logically enough, "one," "two," "three," "four," and "five."
    so what i thought i'd do is put those values into 5 new variables (as to not destroy the old data by accident or what not) and do an old fashioned bubble sort..
    although i can't remember how to do it, and everything i've come up with gives me infinite loops and other such nonsense.
    here's what i have:

    Set Variable: "temp1" = one
    Set Variable: "temp2" = two
    Set Variable: "temp3" = three
    Set Variable: "temp4" = four
    Set Variable: "temp5" = five
    Set Variable: "counter" = 1
    Loop While (counter < 6)
    If ((temp & counter) > (temp & (counter + 1)))

    //that line checks to see if the card "temp1" has a bigger
    //value then card "temp2" - if so, switch their positions:

    Set Variable: temp = temp & (counter + 1)
    Set Variable: temp & (counter + 1) = temp & counter
    Set Variable: temp & counter = temp
    Set Variable: "counter" = 1
    Else
    //if temp1 is LESS than temp2, then it's all good. check
    //the next one
    Set Variable: "counter" = counter + 1
    End If
    End Loop
    If (temp5 = (temp4 + 1) and temp5 = (temp3 + 2) and temp5 = (temp2 + 3) and temp5 = (temp1 + 4))
    Set Variable: "result" = "straight"
    End If

    BUT IT DOESN'T WORK AND I DONT KNOW WHY.
    .....
    help?

    -porksoda

  2. #2
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,092
    Don't remember Bubble Sort.

    But i do remember Les Claypool

  3. #3
    that's cool, cuz i fixed the problem.
    and les claypool is the man.

    -pork

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

HTML5 Development Center