Bubble Sort Algorithm and Arrays

Discussion in 'Software' started by collegestudent2, Nov 19, 2009.

  1. collegestudent2

    collegestudent2 Private E-2

    I am a college student not comprehending the material presented in a basic programming online class. I have completed the assignment below but do not feel confident in what I have written. I would really like someone with more experience to look over it. Thanks!

    Directions: Design a program that asks the user to enter 10 golf scores.
    The scores should be stored in an Integer array. Sort the array in ascending order and display its contents.

    (MUST USE BUBBLE SORT & STORE DATA IN AN ARRAY)




    // Main Module
    Module Main ( )

    // constant array size
    Constant Integer SIZE = 10

    //array to hold golf scores
    Declare Integer golfScores [SIZE]

    // get the golf scores
    getGolfScores (golfScores, SIZE)

    // sort the 10 golf scores
    bubbleSort (golfScores, SIZE)

    // display the golf scores
    Display “The golf scores are”
    Display “Presented from lowest to highest.”
    showGolfScores (golfScores, SIZE)
    End Module



    //create module getGolfScores
    Module getGolfScores (Integer Ref array [ ] , Integer arraySize)
    Declare Integer index
    For index = 0 to arraySize – 1
    Display “enter golf score number “ , index + 1
    Input array [index]
    End For
    End Module

    // create module bubbleSort
    Module bubbleSort (Integer Ref array [ ] , Integer arraySize)
    Declare Integer maxElement
    Declare Integer index
    For maxElement = arraySize – 1 To 0 Step -1
    For index = 0 To maxElement - 1
    If array [index] > array[index + 1] Then
    Call swap(array[index], array[index + 1])
    End if
    End For
    End For
    End Module

    // create module swap
    Module swap (Integer Ref a, Integer Ref b)
    Declare Integer temp
    Set temp = a
    Set a = b
    Set b = temp
    End Module

    //Create module show golf scores
    Module showGolfScores (Integer array [ ] , Integer arraySize)
    Declare Integer index
    For index = 0 to arraySize – 1
    Display array [index]
    End For
    End Module
     
  2. collegestudent2

    collegestudent2 Private E-2

    Is there NO ONE that can help with this??

    I'm really stuck!
     
  3. mjnc

    mjnc MajorGeek

    So, I see you're having fun, huh?

    I looked at your code, but I'm not familiar with that language and
    it's been over 20 years since I did that stuff and that was in BASIC.

    Maybe if you supplied a bit more info. you'll get a useful reply.

    If you are using a compiler, do you get any compile errors?
    Are you able to run the procedure?
    What do you get / see when you run it?
    Do you get any runtime errors?
    Do the results appear to be correct when you input different numbers?

    You can't fix a problem until you find out what the problem is.

    One thing they may not tell you in class is that debugging is an art unto itself.
    I used to get really angry when things didn't go right, but eventually I learned
    that I had to stay calm , analyze what is there and treat it as an interesting challenge.
    Debugging is a skill that you will develop over time through careful trial and error.

    Good luck!
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds