resource sorter() procedure print_array(ref a[1:*] : int) fa i := 1 to ub(a) -> writes(" ", a[i]) af writes("\n") # another way to write a linefeed (terminates above line) end print_array procedure sort(ref a[1:*] : int) # into non-decreasing order fa i := 1 to ub(a)-1, j := i+1 to ub(a) st a[i] > a[j] -> a[i] :=: a[j] /* swap */ af end sort var n : int writes("number of integers? "); read(n) var nums[1:n] : int write("input integers, separated by white space") fa i := 1 to n -> read(nums[i]) af write("original numbers") print_array(nums) sort(nums) write("sorted numbers") print_array(nums) end sorter /* ............... Example compile and run(s) % sr -o sort sort.sr % ./sort number of integers? 5 input integers, separated by white space -10 2 0 100 -77 original numbers -10 2 0 100 -77 sorted numbers -77 -10 0 2 100 */