using namespace std;
typedef struct student
{
int data;
student
*next;
}node;
node
*creat()
{
node
*head,
*p,
*s;
int x=
1,cycle=
1;
head=(node
*)malloc(sizeof(node));
p=head;
while(cycle)
{
cin>>
x;
if(
x!=
0)
{
s=(node
*)malloc(sizeof(node));
s->data=
x;
cout<<
x;
p->
next=
s;
p=
s;
}
else
cycle=
0;
}
head=head->
next;
p->
next=NULL;
return (head);
}
int length(node
*head)
{
int n=
0;
node
*p;
p=head;
while(p!=NULL)
{
n++;
p=p->
next;
}
return n;
}
void
print(node
*head)
{
node
*p;
int n;
n=
length(head);
p=head;
if(head!=NULL)
{
while(p!=NULL)
{
cout<<p->data<<
" ";
p=p->
next;
}
}
}
int main()
{
node * A;
A=creat();
length(A);
print(A);
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-669433.html