#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stu *app(struct stu *head);
float dis(struct stu *head, char *p);
void dele(struct stu *head);
struct stu{
char name[20];
float price;
struct stu *next;
};
int main(void)
{
char c='Y';
char name[20];
float maxprice;
struct stu *head =NULL;
while (c=='Y')
{
head = app(head);
printf("是否继续输入,按Y键继续输入,其他键就结束.\n");
scanf(" %c", &c);
}
maxprice=dis(head,name);
printf("result:\n");
printf("%s %.2f\n",name,maxprice );
dele(head);
return 0;
}
struct stu *app(struct stu *head)
{
struct stu *p=NULL,*pr=head;
char name[20];
float price;
p=(struct stu *)malloc(sizeof(struct stu));
if (p==NULL)
{
exit(0);
}
if (head == NULL)
{
head=p;
}
else
{
while (pr->next != NULL)
{
pr=pr->next;
}
pr->next=p;
}
printf("请输入书名 价格: \n");
scanf("%s %f",name,&price);
strcpy(p->name,name);
p->price=price;
p->next=NULL;
return head;
}
float dis(struct stu *head, char *p)
{
struct stu *pq=head;
float j=0;
while (pq!=NULL)
{
if (pq->price>j)
{
j=pq->price;
strcpy(p,pq->name);
}
pq=pq->next;
}
return j;
}
void dele(struct stu *head)
{
struct stu *p=head , *pr = NULL;
while (p!=NULL)
{
pr=p;
p=p->next;
free(pr);
}
}