#include <stdio.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct node)
struct node
{
int data;
struct node *next;
};
struct node *creat(void)
{
struct node *head=NULL;
struct node *p;
int c;
while((c=getchar())!=EOF)
{
p=(struct node*)malloc(LEN);
if(c=='\n')
continue;
p->data=(char)c;
p->next=NULL;
if(NULL==head)
{
head=p;
}
else
{
struct node *h=head;
while(h->next)
{
h=h->next;
}
h->next=p;
}
}
return(head);
}
struct node *Reversal(struct node *head)
{
struct node *p, *q, *t= NULL;
p = head;
while(q)
{
q=p->next;
p->next=t;
t=p;
p=q;
}
return t;
}
void print(struct node *head)
{
struct node *p;
printf("\tstrings after reverse:\n");
p=head;
if(head!=NULL)
do
{
printf("%c\n",p->data);
p=p->next;
}while(p!=NULL);
}
void main()
{
printf("\t Input the strings:");
struct node *r=creat();
r=Reversal(r);
print(r);
}
森林海
猛跑小猪
相关分类