反向输出每个结点的值


  1. L为不带头结点的单链表,
  2. 编写算法实现从尾到头 反向输出每个结点的值,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "presetNoHead.h"

void rPrint(Node *L) {
if (L != NULL) {
rPrint(L->next);
cout << L->data << " ";
} else {
return;
}
}

int main() {
Node list;
Node *L = &list;
int n;
cout << "enter the length of this linklist : "; cin >> n;
createLinkList(L, n);
cout << "current linklist: " << endl; print(L);
cout << "Reverse order : "; rPrint(L);
return 0;
}