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:

: The sequence to be sorted.`to_be_sorted`

: Indicates the way we want to sort the given sequence. It is indicated by`sort_order`

orascending Members of the sequence are arranged from the smallest member to the largest in value. . They are inbuilt constants of Euphoria’sdescending Members of the sequence are arranged from the largest member to the smallest in value. `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,

**Line 1**: We include the`sort.e`

file.**Lines 4 and 5**: We define the variables.**Lines 8 and 9**: We sort the data in indicated variables and save the outcome.**Lines 12 to 16**: We display necessary details on the screen.

TRENDING TOPICS