Write D code that sorts a list of numbers.
- User
Write D code that sorts a list of numbers.
Assistant
Here is an example of how you can sort a list of numbers in D:
import std.algorithm; void main() { int[] numbers = [1, 5, 2, 6, 3, 7, 4]; numbers.sort(); println(numbers); }This code will sort the list of numbers in ascending order and print the sorted list to the console.
Alternatively, you can use the
sortfunction from thestd.algorithmmodule to sort the list of numbers in descending order:import std.algorithm; void main() { int[] numbers = [1, 5, 2, 6, 3, 7, 4]; numbers.sort(Descending); println(numbers); }This code will sort the list of numbers in descending order and print the sorted list to the console.
You can also use the function from the module to sort the list of numbers in place, without creating a new list:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.