#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
usingnamespace std;
typedefstruct student{
int data;
struct student *next;
}node;
node*create(){
node *head,*p,*s;
int x,cycle=1;
head=(node*)malloc(sizeof(node));
p=head;
while(cycle){
printf("\nPleaseinput the data:");
scanf("%d",&x);
if(x!=0){
s=(node*)malloc(sizeof(node));
s->data=x;
printf("\n%d",s->data);
p->next=s;
p=s;
}else cycle=0;
}
head=head->next;
p->next=NULL;
printf("\n yyy%d",head->data);
return(head);
}
//单链表测长
intlength(node *head){
int count=0;
node *p;
p=head;
while(p!=NULL){
p=p->next;
count++;
}
return(count);
}
//单链表打印
voidprint(node *head){
node *p;
p=head;
while(p!=NULL){
printf("\n%d",p->data);
p=p->next;
}
}
intmain(){
node *head=create();
int a=length(head);
printf("\nlength is%d\n",a);
print(head);
return (0);
}