#include<stdlib.h>
typedef struct node
{
char date;
struct node *next;
}Node,*LinkList;
void CreatList(LinkList *list){
*list=NULL;
}
void HeadInsert(LinkList *list,int length){
int i;
for(i=0;i<length;i++){
LinkList s=(LinkList)malloc(sizeof(Node));
if(s==NULL){
exit(-1);
}
printf("请输入第%d个字符:",i+1);
scanf("%c",&(s->date));
getchar();
s->next=*list;
*list=s;
}
}
void print(LinkList list){
Node *p=list;
for(p;p!=NULL;p=p->next){
printf("%c",p->date);
}
}
void import(LinkList list){
LinkList s1,s2,s3;
if(list == NULL || list->next==NULL){ //空或者只有一个元素不用逆置
return;
}
s1=list;
s2=s1->next;
list=NULL;
while(s2){
s1->next=list;
list=s1;
s1=s2;
s2=s2->next;
}
s1->next=list;
list=s1;
print(list);
}
int main(void){
int N;
LinkList head;
CreatList(&head);
printf("请输入字符个数:\n");
scanf("%d",&N);
getchar();
HeadInsert(&head,N);
printf("链表创建成功,对其遍历\n");
print(head);
printf("\n");
printf("链表逆置之后,对其遍历\n");
import(head);
return 0;
}
01-23
4725
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)