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 ",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(" ");

p = p->next;
}
}

原文地址:https://www.cnblogs.com/wwww2/p/BJFU_204.html