The sort()
method in the Euphoria programming language is used to arrange the members of a sequence in the desired order.
In this method, sorting can be ascending or descending, indicated by the inbuilt constants ASCENDING
and DESCENDING
.
sort(to_be_sorted, sort_order)
The sort()
method takes the following parameters:
to_be_sorted
: The sequence to be sorted.sort_order
: Indicates the way we want to sort the given sequence. It is indicated by sort.e
standard library file. The default value of this parameter is ASCENDING
.To use the sort()
method, we must include the sort.e
file from the standard library of Euphoria like this:
include std/sort.e
This method returns a sorted sequence.
Let’s look at the code below:
include std/sort.e--define variablesconstant model_ages = {18,32,16,23,17,16,25,20,19,32,15}sequence sorted_model_agesASC,sorted_model_agesDESC--store the outcome of sort operationsorted_model_agesASC = sort( model_ages )sorted_model_agesDESC = sort( model_ages,DESCENDING)--print outcome to screenprintf(1,"This is a sort in ASCENDING order: ")print(1,sorted_model_agesASC)puts(1,"\n")printf(1,"This is a sort in DESCENDING order: ")print(1,sorted_model_agesDESC)
In the code above,
sort.e
file.