- 论坛徽章:
- 0
|
新学c,求一个“结构体数组排序的程序”
class Book
{ private :
char * bookname;
char * author;
int salsenumber;
public :
Book(){}
Book(const char * ,const char * ,int);
~Book();
char * getAuthor(){return author;}
char * getName(){return bookname;}
int getSalseNumber(){return salsenumber;}
void setbook(const char * bkname,const char * auth,int snub);
void print(ostream& output);
};
void Booksort(Book bn[],int ns)
{
int i,j,pick;
Book temp;
for(i=0;i<ns-1;i++)
{
pick=i;
for(j=i+1;j<ns;j++)
{
cout<<bn[j].getSalseNumber()<<"-"<<bn[pick].getSalseNumber()<<endl;
if(bn[j].getSalseNumber()>;bn[pick].getSalseNumber())
pick=j;
}
temp=bn;
bn=bn[pick];
bn[pick].setbook(temp.getName(),temp.getAuthor(),temp.getSalseNumber());
}
} |
|