BJFU—214基于链式存储结构的图书信息表的创建和输出
#include<stdio.h>
#include<stdlib.h>
#define max 100
typedef struct bnode
{
double no;
char name[max];
double price;
struct bnode * next;
}bnode,*blnode;
blnode createdata(blnode b);
void traverse(blnode b);
int main()
{
blnode book;
book = createdata(book);
traverse(book);
return 0;
}
blnode createdata(blnode b)
{
b = (blnode)malloc(sizeof(bnode));
b->next = null;
blnode ptai = b;
int count = 0;
while(1)
{
blnode pnew = (blnode)malloc(sizeof(bnode));
scanf("%lf",&pnew->no);
scanf("%s",&pnew->name);
scanf("%lf",&pnew->price);
if(pnew->no==0&&pnew->name[0]=='0'&&pnew->price==0)
break;
ptai->next = pnew;
ptai = pnew;
ptai->next = null;
count++;
}
printf("%d\n",count);
return b;
}
void traverse(blnode b)
{
blnode p = b;
while(p->next!=null)
{
printf("%.0f ",p->next->no);
printf("%s ",p->next->name);
printf("%.2f",p->next->price);
printf("\n");
p = p->next;
}
}