#include "head.h"
int main(int argc, const char *argv[])
{
struct Che *p=Space();
In(p,5);
Bubble(p,5);
Out(p,5);
Free(p);
p=NULL;
return 0;
}
#ifndef N
#define N
#include <stdio.h>
#include <stdlib.h>
struct Che
{
char name[10];
char color[10];
int price;
};
struct Che *Space(void);
void In(struct Che *p,int n);
void Bubble(struct Che *p,int n);
void Out(struct Che *p,int n);
struct Che *Free(struct Che *p);
#endif
#include "head.h"
struct Che *Space(void)
{
struct Che *p=(struct Che *)malloc(sizeof(struct Che)*5);
return p;
}
void In(struct Che *p,int n)
{
for(int i=0;i<n;i++)
{
printf("输入品牌:");
scanf("%s",(p+i)->name);
printf("输入颜色:");
scanf("%s",(p+i)->color);
printf("输入价格:");
scanf("%d",&(p+i)->price);
}
}
void Bubble(struct Che *p,int n)
{
int i,j,count=0;
struct Che t;
for(i=1;i<n;i++)
{
count=0;
for(j=0;j<n-i;j++)
{
if((p+j)->price<(p+j+1)->price)
{
t=*(p+j);
*(p+j)=*(p+j+1);
*(p+j+1)=t;
}
}
if(count==0)
{
break;
}
}
}
void Out(struct Che *p,int n)
{
for(int i=0;i<n;i++)
{
printf("品牌:%s,颜色:%s,价格:%d\n",(p+i)->name,(p+i)->color,(p+i)->price);
}
}
struct Che *Free(struct Che *p)
{
free(p);
return p;
}