...
/Solution: Sort and Reverse Elements of an Array
Solution: Sort and Reverse Elements of an Array
This lesson provides a solution to the challenge given in the previous lesson.
We'll cover the following...
Solution #
Here is the code that will sort and reverse elements of an array.
Press + to interact
import std.stdio;import std.algorithm;void SortAndReverse() {int[] values=[ 20, 13, 4, 9, 11 ];// The counter is commonly named as 'i'int i;writeln("Sorted Elements: ");sort(values);i = 0;while (i < values.length) {write(values[i], " ");++i;}writeln();writeln("Reversed Elements: ");reverse(values);i = 0;while (i < values.length) {write(values[i], " ");++i;}writeln();}