#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
struct node
{
char a;
struct node *next;
};
int main()
{
struct node *p,*q,*h,*t;
int count=0,j;
h = (struct node*)malloc(sizeof(struct node));
p = (struct node*)malloc(sizeof(struct node));
q = (struct node*)malloc(sizeof(struct node));
h->next = p;
char b[10];
printf(“请输入一行字符:\n”);
gets(b);
for(int i=0;b[i]!=’\0′;i++)
{
p->a = b[i];
p->next = q;//链接
p = p->next;//p指向下一个
q = (struct node*)malloc(sizeof(struct node));
count++;
}
p->next = NULL;
free(q);
while(1)
{
j=1;//t指向第一个结点,所以从1开始计数
t = h->next;
while(j!=count)
{
j++;
t = t->next;
}
count–;//逆序输出
printf(“%c”,t->a);
free(t);
if (count ==0)
break;
}
return 0;
}