用c语言实现对于不带头结点的单链表L,设计一个递归算法逆序输出所有结点值
时间: 2023-05-26 22:02:13 浏览: 145
字符串的组合算法问题的C语言实现攻略
```
#include<stdio.h>
struct Node {
int data;
struct Node* next;
};
void reverse_print(struct Node* head) {
if (head == NULL) {
return;
}
reverse_print(head->next);
printf("%d ", head->data);
}
int main() {
struct Node node1 = { 1, NULL };
struct Node node2 = { 2, NULL };
struct Node node3 = { 3, NULL };
struct Node node4 = { 4, NULL };
node1.next = &node2;
node2.next = &node3;
node3.next = &node4;
struct Node* head = &node1;
reverse_print(head);
return 0;
}
```
阅读全文