Reversing a List program in cpp

#include <iostream>
#include <list>
void print(std::list<char> const &list)
{
    for (auto it = list.crbegin(); it != list.crend(); it++) {
        std::cout << *it << ' ';
    }
}
int main()
{
    std::list<char> list = { 'x', 'y', 'z' };
    print(list);
    return 0;
}

OUTPUT:

z y x

Leave a Comment