Created
February 27, 2024 07:50
-
-
Save ehlzi/5a741e892e1a767ba00d96c287f7fe08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Module Main(); | |
| // Constants | |
| Constant Integer size = 10; | |
| // Array to hold golf scores | |
| Declare Integer golfScores[size]; | |
| // Get the golf scores from user | |
| Call GetGolfScores(golfScores, size); | |
| // Sort the golf scores in ascending order | |
| Call SelectionSort(golfScores, size); | |
| // Display the sorted golf scores | |
| Display "Here are the golf scores from lowest to highest:"; | |
| Call ShowGolfScores(golfScores, size); | |
| End Module; | |
| Module GetGolfScores(Ref Integer array[], Integer arraySize); | |
| // Variable for index | |
| Declare Integer index; | |
| // Prompt user for golf scores | |
| For index = 0 To arraySize - 1 Do | |
| Display "Enter golf score #" + (index + 1) + ":"; | |
| Input array[index]; | |
| EndFor; | |
| End Module; | |
| Module SelectionSort(Ref Integer array[], Integer arraySize); | |
| // Variables to hold positions during selection sort | |
| Declare Integer startScan, minIndex, minValue, index; | |
| // Selection sort algorithm | |
| For startScan = 0 To arraySize - 2 Do | |
| Set minIndex = startScan; | |
| Set minValue = array[startScan]; | |
| For index = startScan + 1 To arraySize - 1 Do | |
| If array[index] < minValue Then | |
| Set minValue = array[index]; | |
| Set minIndex = index; | |
| EndIf; | |
| EndFor; | |
| // Swap the elements | |
| Call Swap(array[minIndex], array[startScan]); | |
| EndFor; | |
| End Module; | |
| Module Swap(Ref Integer a, Ref Integer b); | |
| // Temporary storage | |
| Declare Integer temp; | |
| // Swap the values | |
| Set temp = a; | |
| Set a = b; | |
| Set b = temp; | |
| End Module; | |
| Module ShowGolfScores(Integer array[], Integer arraySize); | |
| // Counter variable | |
| Declare Integer index; | |
| // Display the golf scores | |
| For index = 0 To arraySize - 1 Do | |
| Display array[index]; | |
| EndFor; | |
| End Module; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment