Logo

Programming-Idioms

History of Idiom 19 > diff from v29 to v30

Edit summary for version 30 by Dodopod:
New C implementation by user [Dodopod]

Version 29

2017-05-14, 03:52:24

Version 30

2017-05-27, 19:05:34

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
int *p1 = x;
int *p2 = x + N-1;

while (p1 < p2)
{
    int temp = *p1;
    *(p1++) = *p2;
    *(p2--) = temp;
}
Comments bubble
Reverses an array of N ints, in-place.