C++练习 | 单链表的创建与输出(结构体格式)
标签:cout ios def new book price 结构体 单链表 bsp
#include
#include using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
int num=0;
typedef struct Book
{
string IS;
string Name;
float price;
Book *next;
}Book,*PBook;
PBook Create()
{
PBook Head=new Book;
PBook Tail=new Book;
PBook New;
string t1,t2;
float t3;
Tail=Head;
while(cin>>t1>>t2>>t3&&t3)
{
num++;
New=new Book;
New->IS=t1;
New->Name=t2;
New->price=t3;
Tail->next=New;
New->next=NULL;
Tail=New;
}
return Head;
}
void Print(PBook pHead)
{
PBook p;
p=pHead->next;
coutendl;
while(p!=NULL)
{
coutIS" "Name;
printf(" %.2f\n",p->price);
p=p->next;
}
}
int main()
{
PBook Head;
Head=Create();
Print(Head);
return 0;
}
C++练习 | 单链表的创建与输出(结构体格式)
标签:cout ios def new book price 结构体 单链表 bsp
原文地址:https://www.cnblogs.com/tsj816523/p/11546430.html
评论