你里面本来就是反着弄的。
#include
#include
#define datatype int
//结点类型定义
typedef struct node
{
datatype data;
struct node *next;
}linklist, lnode;
linklist *CREATLISTF()
{
char ch;
int i = 1;
linklist *head, *s, *p;
head = NULL;
ch = getchar();//读入第一个结点的值
//输入'$'时结束
while (ch != '$'){
//printf("%d ", s->data);
s = (linklist*)malloc(sizeof(linklist));//生成新结点
if(i == 1)
{
head = s;
p = s;
i = 0;
}
else
{
p->next = s;
p = s;
p->next = NULL;
}
s->data = ch;
ch = getchar();
ch = getchar();
}
return head;//返回链表头指针
}
int main(){
linklist *L;
lnode *p;
L = CREATLISTF();
p = L;
while(p != NULL){
printf("%c", p->data);
p = p->next;
}
return 0;
}
头插法,本来就是反的 。本来是头的变成尾了。输出是反的