逆置单链表的输出不完整
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef struct ListNode{
char data;
struct ListNode *next;
}*plist,node;
plist creat_list(int nodenum){
plist l=(plist)malloc(sizeof(node));
plist temp,p;
char ch;
int i;
temp=l;
printf("Please input the elements:\n");
getchar();
for(i=0;i<nodenum;i++){
ch=getchar();
p=(plist)malloc(sizeof(node));
p->data=ch;
p->next=NULL;
temp->next=p;
temp=p;
}
return l;
}
void display(plist input){
plist temp;
temp=input->next;
while(temp!=NULL){
printf("%c ",temp->data);
temp=temp->next;
}
printf("\n");
return;
}
void reverseit(plist cur,plist *L){
plist next=NULL;
if(cur->next==NULL){
*L=cur;
}
else{
next=cur->next;
reverseit(next,L);
next->next=cur;
cur->next=NULL;
}
return;
}
int main()
{
int nodenum,i;
char ele;
plist L,temp;
L=(plist)malloc(sizeof(node));
printf("Please input the element number that is no less than 1:\n");
scanf("%d",&nodenum);
//生成链表
L=creat_list(nodenum);
//打印链表
printf("L:");
display(L);
//逆置链表
temp=L;
reverseit(temp,&L);
//打印逆置后的链表
printf("逆置L:\n");
display(L);
return 0;
}