[面试] 从尾到头打印链表-递归实现

/* 05_从尾到头打印链表 */
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
struct Node {
    int value;
    Node* next;
    Node() {}
    Node(int k) : value(k) {}
};
Node* creat_list(Node* p) {
    Node* top = p;
    for (int i = 1; i <= 9; i++) {
        p->next = new Node(i);
        p = p->next;
    }
    return top;
}
void re_print(Node* p) {
    if (p->next) {
        re_print(p->next);
    }
    cout << p->value << "->";
}
int main() {
    Node *ph = new Node();
    ph = creat_list(ph);
    re_print(ph);
    cout << "NULL" << endl;
    return 0;
}

原文地址:https://www.cnblogs.com/robbychan/p/3786914.html