Last active
February 27, 2024 07:51
-
-
Save ehlzi/af1be9718ef322d0a8a5940a3bf352eb 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 = 20; | |
| // Array to hold names | |
| Declare String names[SIZE]; | |
| // Get names from user | |
| Call GetNames(names, SIZE); | |
| // Sort the names in ascending (alphabetical) order | |
| Call SelectionSortStrings(names, SIZE); | |
| // Display the sorted names | |
| Display "Sorted names in alphabetical order:"; | |
| Call ShowNames(names, SIZE); | |
| End Module; | |
| Module GetNames(Ref String array[], Integer arraySize); | |
| // Variable for index | |
| Declare Integer index; | |
| // Prompt user for names | |
| For index = 0 To arraySize - 1 Do | |
| Display "Enter name #" + (index + 1) + ":"; | |
| Input array[index]; | |
| EndFor; | |
| End Module; | |
| Module SelectionSortStrings(Ref String array[], Integer arraySize); | |
| // Variables to hold positions during selection sort | |
| Declare Integer startScan, minIndex; | |
| Declare String minValue; | |
| Declare Integer index; | |
| // Selection sort algorithm for strings | |
| 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 SwapStrings(array[minIndex], array[startScan]); | |
| EndFor; | |
| End Module; | |
| Module SwapStrings(Ref String a, Ref String b); | |
| // Temporary storage | |
| Declare String temp; | |
| // Swap the strings | |
| Set temp = a; | |
| Set a = b; | |
| Set b = temp; | |
| End Module; | |
| Module ShowNames(String array[], Integer arraySize); | |
| // Counter variable | |
| Declare Integer index; | |
| // Display the names | |
| 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