#include #include using namespace std; int main() { int a[] = {20, 10, 50, 30, 40}; const size_t n = sizeof a / sizeof a[0]; for (int *end = a + n - 1; a < end; --end) { for (int *p = a; p < end; ++p) { if (p[1] < p[0]) { //if p[0] and p[1] in wrong order, const int temp = p[0]; //swap them p[0] = p[1]; p[1] = temp; } } } for (int *p = a; p < a + n; ++p) { cout << *p << "\n"; } return EXIT_SUCCESS; }