好的,这是路易斯安那大学东南部 CMPS 280 测试中的额外问题。三行反向打印单向链表。有任何想法吗?
最佳答案
C 实现您的奖金问题,分三行:
#include <stdio.h>
struct node {
int data;
struct node* next;
};
void ReversePrint(struct node* head) {
if(head == NULL) return;
ReversePrint(head->next);
printf("%d ", head->data);
}
int main()
{
struct node first;
struct node second;
struct node third;
first.data = 1;
second.data = 2;
third.data = 3;
first.next = &second;
second.next = &third;
ReversePrint(&first); // Should print: 3 2 1
printf("\n");
return 0;
}
关于recursion - 以相反的顺序打印单向链表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27047351/