编辑代码

#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 10000 //图书表可能达到的最大长度
typedef struct //图书信息定义
{
	char no[20]; //图书 ISBN
	char name[50]; //图书名字
	float price; //图书价格
}Book;
typedef struct LNode
{
	Book data; //结点的数据域
	struct LNode *next; //结点的指针域
}LNode,*LinkList; //LinkList 为指向结构体 LNode 的指针类型
LinkList createformtail(LinkList list,int n){
	list=(LNode*)malloc(sizeof(LNode));
	list->next=NULL;
	LNode *r,*s;
	r=list;
	for(int i=0;i<n;i++){
		Book book;
		s=(LNode*)malloc(sizeof(LNode));
		s->next=NULL;
		printf("请输入第%d本图书的ISBN:\n",i+1);
		scanf("%s",&book.no);
		printf("请输入第%d本图书的名称:\n",i+1);
		scanf("%s",&book.name);
		printf("请输入第%d本图书的价格:\n",i+1);
		scanf("%f",&book.price);
		s->data=book;
		r->next=s;
		r=s;
	}
	r->next=NULL;
	return list;
}
void printlist(LinkList list){
	list=list->next;
    printf("ISBN\t名称\t价格\n");
	while(list!=NULL){
		printf("%s\t%s\t%.2f\n",list->data.no,list->data.name,list->data.price);
		list=list->next;
	}
}
void sortbyprice(LinkList list){

    LNode *i=list->next;
    while(i!=NULL){
        LNode *j=i->next;
        while(j!=NULL){
            if(i->data.price<j->data.price){
                Book temp;
                temp=i->data;
                i->data=j->data;
                j->data=temp;
            }
            j=j->next;
        }
        i=i->next;
    }
}
int getlength(LinkList list){
    LNode *head=list->next;
    int length=0;
    while(head){
        length++;
        head=head->next;
    }
    return length;
}
void changeprice(LinkList list){
    LNode *head=list->next;
    double mean=0;
    while(head){
        mean+=head->data.price;
        head=head->next;
    }
    int length=getlength(list);
    mean/=length;
    head=list->next;
    while(head){
        if(head->data.price<mean){
            head->data.price=1.2*head->data.price;
        }
        else{
            head->data.price=1.1*head->data.price;
        }
        head=head->next;
    }
}
LinkList contarycreate(LinkList list,int n){
    list=(LNode*)malloc(sizeof(LNode));
    LNode *p,*s;
    p=(LNode*)malloc(sizeof(LNode));
    list->next=p;
    p->next=NULL;
    Book book;
    printf("请输入第%d本图书的ISBN:\n",1);
    scanf("%s",&book.no);
    printf("请输入第%d本图书的名称:\n",1);
    scanf("%s",&book.name);
    printf("请输入第%d本图书的价格:\n",1);
    scanf("%f",&book.price);
    p->data=book;
    for(int i=0;i<n-1;i++){
		Book book;
		s=(LNode*)malloc(sizeof(LNode));
		printf("请输入第%d本图书的ISBN:\n",i+2);
		scanf("%s",&book.no);
		printf("请输入第%d本图书的名称:\n",i+2);
		scanf("%s",&book.name);
		printf("请输入第%d本图书的价格:\n",i+2);
		scanf("%f",&book.price);
		s->data=book;
		list->next=s;
        s->next=p;
		p=s;
	}
    return list;
}
void findexpensive(LinkList list){
    LNode *head=list->next;
    double exprice=-99999;
    while(head){
        if(exprice<head->data.price){
            exprice=head->data.price;
        }
        head=head->next;
    }
    head=list->next;
    int cnt=0;
     while(head){
        if(exprice==head->data.price){
            cnt++;
        }
        head=head->next;
    }
    printf("价格最高为%.2f,一共有%d本\n",exprice,cnt);
    head=list->next;
     while(head){
        if(exprice==head->data.price){
            printf("%s\t%s\t%.2f\n",head->data.no,head->data.name,head->data.price);
        }
        head=head->next;
    }
}
void findlovest(LinkList list){
    int n,length=getlength(list);
    char findname[length][50];
    printf("请输入您需要查找图书数目:\n");
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        printf("请输入图书名称:\n");
        scanf("%s",&findname[i]);
    }
    for(int i=0;i<n;i++){
        char name[50];
        strcpy(name,findname[i]);
        LNode *head=list->next;
        int cnt=0;
        while(head){
        if(strcmp(name,head->data.name)==0){
            cnt++;
        }
        head=head->next;
        }   
        printf("您最爱的书:%s,一共有%d本\n",name,cnt);
        head=list->next;
        while(head){
        if(strcmp(name,head->data.name)==0){
            printf("%s\t%s\t%.2f\n",head->data.no,head->data.name,head->data.price);
        }
        head=head->next;
    }
    }
}
LNode* getbook(LinkList list,int index){
   int cnt=0;LNode *p; p=list->next;
    while(cnt!=index){
        cnt++;
        if(p->next){
        p->next;
        }
    }
    return p;
}
void findbestindex(LinkList list){
    int n=0;int length;length=getlength(list);length-=1;
    printf("请输入你要查询的图书次数\n");
    scanf("%d",&n);int num[n];LNode *p;
    for(int i=0;i<n;i++){
        scanf("%d",&num[i]);
    }
    for(int i=0;i<n;i++){
        num[i]-=1;
        if(num[i]>length||num[i]<0){
            printf("您查询的序号%d:抱歉,最佳位置上的图书不存在!",num[i]+1);
        }
        else{
        p=getbook(list,num[i]);
         printf("您查询的序号%d:%s\t%s\t%.2f\n",num[i]+1,p->data.no,p->data.name,p->data.price);
    }
    }
}
void bookadd(LinkList list){
        
}
int main(void)
{
	LinkList library;
	int num=0;
    printf("请输入图书数量\n");
    scanf("%d",&num);
    library=contarycreate(library,num);
    changeprice(library);   
    printlist(library);
    findexpensive(library);
    bookadd(library);
    printlist(library);
}