• C++练习 | 单链表的创建与输出(结构体格式)


    #include <iostream>
    #include <stdio.h>
    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;
        cout<<num<<endl;
        while(p!=NULL)
        {
            cout<<p->IS<<" "<<p->Name;
            printf(" %.2f
    ",p->price);
            p=p->next;
        }
    }
    
    int main()
    {
        PBook Head;
        Head=Create();
        Print(Head);
        return 0;
    }
  • 相关阅读:
    Servlet开发
    HTML实现页面自动跳转的五种方法
    AVAYA话机管理
    AVAYA路由
    报关相关知识
    基本杆法
    AVAYA初始配置
    加塞和瞄准
    基本杆法图解
    AVAYA拨号计划
  • 原文地址:https://www.cnblogs.com/tsj816523/p/11546430.html
Copyright © 2020-2023  润新知