欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

BJFU—214基于链式存储结构的图书信息表的创建和输出

程序员文章站 2022-06-20 22:14:47
#include#include#define MAX 100 typedef struct bNode{ double no; char name[MAX]; double price; struct bNode * next;}bNode,*bLnode; ......

#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;
}
}