carl
This commit is contained in:
70
tests/carl/NoErrors/selectionSort.alpha.asc
Normal file
70
tests/carl/NoErrors/selectionSort.alpha.asc
Normal file
@ -0,0 +1,70 @@
|
||||
alpha parser, version 0.2 (2023-03-04) - Annotated Source Code for file selectionSort.alpha
|
||||
001: (* Type definitions *)
|
||||
002:
|
||||
003: type string2int: string -> integer
|
||||
004: type intArray: 1 -> integer
|
||||
005: type intArrayXinteger: [ intArray: data; integer: index ]
|
||||
006: type intArrayXinteger2integer: intArrayXinteger -> integer
|
||||
007: type intArray2Boolean: intArray -> Boolean
|
||||
008:
|
||||
009:
|
||||
010: (* Function declarations
|
||||
011: They use the above type definitions
|
||||
012: *)
|
||||
013: function indexOfSmallest: intArrayXinteger2integer
|
||||
014: function selectionSort: intArray2Boolean
|
||||
015: function entry : string2int
|
||||
016:
|
||||
017: (* indexOfSmallest *)
|
||||
018: indexOfSmallest (* as *) (data, startingIndex) := {
|
||||
019: [ integer: indexOfSmallestSoFar; integer: i ]
|
||||
020: indexOfSmallestSoFar := startingIndex;
|
||||
021: i := 0 ;
|
||||
022: while (i < data._1 ) {
|
||||
023: if ( data(i) < data(indexOfSmallestSoFar) )
|
||||
024: then {
|
||||
025: indexOfSmallestSoFar := i;
|
||||
026: }
|
||||
027: else {
|
||||
028: i := i;
|
||||
029: }
|
||||
030: i := i + 1;
|
||||
031: }
|
||||
032: return indexOfSmallestSoFar;
|
||||
033: }
|
||||
034:
|
||||
035:
|
||||
036: (* selectionSort *)
|
||||
037: selectionSort(data) := {
|
||||
038: [ integer: i ]
|
||||
039: i := 0 ;
|
||||
040: while (i < data._1 ) {
|
||||
041: [ integer: index; integer: temp ]
|
||||
042: index := indexOfSmallest(data,i);
|
||||
043: temp := data(index);
|
||||
044: data(index) := data(i);
|
||||
045: data(i) := temp;
|
||||
046: i := i + 1;
|
||||
047: }
|
||||
048: return true;
|
||||
049: }
|
||||
050:
|
||||
051:
|
||||
052: (* Function definition
|
||||
053: entry is the first function called
|
||||
054: *)
|
||||
055: entry(arg) := {
|
||||
056: [ intArray: data; Boolean: _ ]
|
||||
057: data := reserve data(8);
|
||||
058: data(0) := 60;
|
||||
059: data(1) := 80;
|
||||
060: data(2) := 10;
|
||||
061: data(3) := 50;
|
||||
062: data(4) := 30;
|
||||
063: data(5) := 40;
|
||||
064: data(6) := 20;
|
||||
065: data(7) := 70;
|
||||
066: _ := selectionSort(data);
|
||||
067: return 0;
|
||||
068: }
|
||||
069:
|
Reference in New Issue
Block a user