Quick actions

cmd+k|ctrl+k

Navigation

Languages

Print sorted arrays in ascending order

Snippet info

Language

Cpp

Visibility

public

Author

mrsimb

Created

2017-09-04T22:37:38Z

Updated

2017-09-05T14:04:04Z

#include <iostream>
using namespace std;

void print_sorted_arrays_ascending(int *a, int alen, int *b, int blen) {
    while (alen || blen) {
        bool should_print_a = (alen && blen) ? (*a < *b) : alen;
        cout << (should_print_a ? (--alen, *a++) : (--blen, *b++)) << '\n';
    }
}

int main() {
    int a[] = {0, 2, 4, 7, 8};
    int b[] = {1, 3, 5, 6};
    
    int alen = sizeof(a) / sizeof(*a);
    int blen = sizeof(b) / sizeof(*b);
    
    print_sorted_arrays_ascending(a, alen, b, blen);
    
    return 0;
}
INFO