#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
};
void insertNode(Node*& head, int value) {
Node* newNode = new Node;
newNode->data = value;
newNode->next = nullptr;
if (head == nullptr) {
head = newNode;
} else {
Node* temp = head;
while (temp->next != nullptr) {
temp = temp->next;
}
temp->next = newNode;
}
}
void printList(Node* head) {
Node* temp = head;
while (temp != nullptr) {
cout << temp->data << " ";
temp = temp->next;
}
cout << endl;
}
void reversePrint(Node* head) {
if (head == nullptr) {
return;
}
reversePrint(head->next);
cout << head->data << " ";
}
void deleteList(Node*& head) {
Node* temp;
while (head != nullptr) {
temp = head;
head = head->next;
delete temp;
}
}
int main() {
Node* head = nullptr;
int value;
while (cin >> value) {
insertNode(head, value);
}
cout << "正序打印:";
printList(head);
cout << "逆序打印:";
reversePrint(head);
cout << endl;
deleteList(head);
return 0;
}