#include"stdio.h"
#include"stdlib.h"
struct node //结点
{
char cha;
struct node *next;
}*a_to_z;
struct node * insert(struct node *p)//插入b,c...z构建链表
{
int a = 97;
while(a<=121)
{
struct node *new;
new = (struct node *)malloc(sizeof(struct node));
a++;
new->cha = a;
new->next = NULL;
p->next = new;
p= p->next;
}
}
void my_printf(struct node *p)//打印
{
while(p != NULL)
{
printf("%c ",p->cha);
p= p->next;
}
printf("\n");
}
struct node * rever(struct node *p)//逆序
{
int i = 0;
int count = 0;
struct node *head;
struct node *last;
head = last = p;
while(last->next!=NULL)
{
last = last->next;
count++;
}
count++;
struct node **array=(struct node **)malloc(sizeof(struct node*)*count);
for(i = 0;i < count;i++,head = head->next)//将结点放在数组中
{
array[i] = head;
}
for(i = (count-1);i>0;i--)//将数组中语速逆序连接
{
array[i]->next = array[i-1];
}
array[0]->next = NULL;
return array[count-1];
}
int main()
{
struct node *reverse;
a_to_z = (struct node *)malloc (sizeof(struct node));
a_to_z->cha = 'a';
a_to_z->next = NULL;
insert(a_to_z);
printf("建立链表:\n");
my_printf(a_to_z);
printf("逆序并输出:\n");
reverse = rever(a_to_z);
my_printf(reverse);
return 0;
}