works:programmer:cpp:array-reverse
Pure C Array Reverse using Pointer
#include <iostream> #include <string> using namespace std; void array_reverse(int* ch, int len) { int n = len / 2; for ( int i=0 ; i<n; i++ ) { int tmp = ch[len-i-1]; ch[len-i-1] = ch[i]; ch[i] = tmp; } } int main() { int items[] = {0, 1, 2, 3, 4, 5, 6}; array_reverse(items, 7); for (int i: items) { cout << i << endl; } }
works/programmer/cpp/array-reverse.txt · Последнее изменение: 2020/01/15 17:35 — 127.0.0.1