Logo

Programming-Idioms

History of Idiom 19 > diff from v10 to v11

Edit summary for version 11 by :

Version 10

2015-08-22, 07:37:03

Version 11

2015-08-22, 07:39:15

Idiom #19 Reverse a list

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

Idiom #19 Reverse a list

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

Code
var n,i: integer;
	tmp:TElement;
[...]
n:= length(x);
for i := 0 to (n div 2)-1 do
	begin
		tmp := x[i];
		x[i] := x[n-i-1];
		x[n-i-1] := tmp;
	end;
Comments bubble
alternative implementation, if the type of the elements is known.