1.从尾到头打印链表
题目描述:
思路分析:
- 首先创建带头结点的单链表,采用尾插法顺序建表
- 逆序输出,容易想到的方法有递归或者借助栈结构来实现
- 此处采用递归
代码实现:
#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
int data;
struct Node *next;
}node;
node* CreatLinkList(int n)
{
int i,x;
node *head = (node *)malloc(sizeof(node));
head->next = NULL;
node *tail = head;
for(i = 0;i < n;i++)
{
printf("please input data:");
scanf("%d",&x);
node *s = (node *)malloc(sizeof(node));
s->data = x;
s->next = tail->next;
tail->next = s;
tail = s;
}
return head;
}
void ReverseDisplay(node *