65,186
社区成员




#include "iostream.h"
struct node
{
char data;
node *next;
};
node * create();
void showList(node *head);
node * create()
{
node *head=NULL;
node *pEnd=head;
node *pS;
char temp;
cout <<"Please input a string end with '#':" <<endl;
do
{
cin >>temp;
if (temp!='#')
{
pS=new node;
pS->data=temp;
pS->next=NULL;
if (head==NULL)
{
head=pS;
}
else
{
pEnd->next=pS;
}
pEnd=pS;
}
}
while (temp!='#');
return head;
}
void showList(node *head)
{
node *pRead=head;
cout <<"The data of the link list are:" <<endl;
while (pRead!=NULL)
{
cout <<pRead->data;
pRead=pRead->next;
}
cout <<endl;
}
int main()
{
node *head;
head=create();
showList(head);
return 0;
}