如题,代码如下:
#include <stdio.h>
#include <stdlib.h>
//链表类型
typedef struct list_t
{
int data;
struct list_t *next;
}list_t;
list_t *create_list (int n);
void print_list (list_t *head);
void re_print_list(list_t *head);
int main(int argc, char *argv[])
{
int n = 0;
list_t *head = NULL;
scanf("%d", &n);
head = create_list(n);
printf("\n");
print_list(head);
printf("\n");
re_print_list(head);
printf("\n");
return 0;
}
//创建链表
list_t *create_list(int n)
{
list_t *list_node = NULL;
if (n > 0) {
list_node = (list_t *)malloc(sizeof(list_t));
if (!list_node) {
perror("memory is full!");
exit(-1);
}
scanf("%d", &list_node->data);
list_node->next = create_list(n - 1);
}
retu