Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • D

Idiom #19 Reverse a list

Reverse the order of the elements of the list x.
This may reverse "in-place" and destroy the original ordering.

import std.range;
auto y = x.retro;

This doesn't allocate a new list or modify the original, but creates an iterator that traverses the list in reverse order.
import std.algorithm;
reverse(x);

Reverses x in-place.
with Ada.Containers.Vectors;
use Ada.Containers;
X.Reverse_Elements;

New implementation...
< >
programming-idioms.org