#include <iostream>
using namespace std;

struct List {
	int value = 0;
	List* next = nullptr;
	List(int x) : value(x) {}
};

List* reverse(List* head) {
	List* next = head->next;
	head->next = nullptr;
	while (next != nullptr) {
		List* movingHead = next->next;
		next->next = head;
		head = next;
		next = movingHead;
	}
	return head;
}

int main() {
	List* head = new List(1);
	List* list = head;
	for (int index = 2; index < 10; index++) {
		List* next = new List(index);
		list->next = next;
		list = next;
	}
	head = reverse(head);
	
	while (head != nullptr) {
		printf("%d\n", head->value);
		head = head->next;
	}
	return 0;
}