其他分享
首页 > 其他分享> > BJFU-217-基于链式存储结构的图书信息表的逆序存储

BJFU-217-基于链式存储结构的图书信息表的逆序存储

作者:互联网

这道题可以用头插法创建列表,然后正常输出:

#include<stdio.h>
#include<stdlib.h>
#define MAX 100

typedef struct Book{
    double no;
    char name[MAX];
    double price;
    struct Book * next;
}Book,*BList;
//头插法创建链表
void CreatList(BList &B)
{
    B = (BList)malloc(sizeof(Book));
    B->next = NULL;
    BList rear = B;
    int n;
    scanf("%d",&n);

    for(int i=1;i<=8;i++)
    {
       BList p = (BList)malloc(sizeof(Book));
       scanf("%lf",&p->no);
       scanf("%s",p->name);
       scanf("%lf",&p->price);
       if(p->no==0&&p->name[0]=='0'&&p->price==0) break;
       p->next = rear->next;
       rear->next = p;
    }
}
void traverse(BList B)
{
    BList p = B->next;
    while(p)
    {
        printf("%.0f ",p->no);
        printf("%s ",p->name);
        printf("%.2f",p->price);
        printf("\n");
        p = p->next;
    }
}

int main()
{
    BList B;
    CreatList(B);
    traverse(B);
    return 0;
}

 

标签:217,存储,name,price,printf,next,Book,BJFU,BList
来源: https://www.cnblogs.com/wwww2/p/11745479.html