BJFUOJ:基于链式存储结构的图书信息表的创建和输出
代码
#include <bits/stdc++.h>
using namespace std;
int i = 0;
struct book{
string bookno;
string name;
double price;
};
typedef struct Lnode{
book data;
struct Lnode *next;
}Lnode,*Linklist;
void Init_list(Linklist &l){
l = new Lnode;
l->next = NULL;
}
int input(Linklist &l){
string bookno;
string name;
double price;
Linklist p,q;
p = l;
while(cin>>bookno>>name>>price){
if(bookno == "0" && name == "0" && price == 0) break;
q = new Lnode;
q->data.bookno = bookno;
q->data.name = name;
q->data.price = price;
p->next = q;
q->next = NULL;
p = q;
i++;
}
return i;
}
void output(Linklist &l){
Linklist r = l->next;
while(r){
cout<<r->data.bookno<<" "<<r->data.name<<" ";
printf("%.2lf\n",r->data.price);
r = r->next;
}
}
int main(){
Linklist l;
Init_list(l);
int n = input(l);
cout<<n<<endl;
output(l);
return 0;
}
版权声明:本文为qq_19830591原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。