#include #include using namespace std; void print(const list& alist); void reverse(list& alist); int main() { list alist; for (int i = 1; i <= 9; i++) alist.push_back(10*i); print(alist); reverse(alist); print(alist); } void print(const list& alist) { for (list::const_iterator it = alist.begin(); it != alist.end(); it++) { cout << *it << " "; } cout << endl; } void reverse(list& alist) { if (alist.size() <= 1) return; int first = alist.front(); alist.erase(alist.begin()); // remove the first element reverse(alist); // reverse the rest of the list alist.push_back(first); // append the first element at the end }