您的位置:程序门 -> c/c++ ->



冒泡法中形参数组类型如果是属于一个类的怎么写


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


冒泡法中形参数组类型如果是属于一个类的怎么写[已结贴,结贴人:hyd198471]
发表于:2007-05-28 22:29:37 楼主
class   parkbox
{
private:
char*   license_plate;
public:
parkbox();
parkbox(char*);
~parkbox(){delete   []license_plate;}
char*   get_license_plate();
char*   set_license_plate(char*);
};
class   parkinggarage
{
parkbox     *parkbox[boxes];
void   bubble_sort(parkbox   *pa[],int   dimension)//数组类型是parkbox型的下面程序的赋值符号没有定义这个私有函数怎么写
{
int   i,j;
        parkbox   temp;
for(i=0;i <dimension;i++)
{
for(j=i+1;j <dimension;j++)
{
if(pa[j]   >   pa[i])
{
temp=pa[i];
pa[i]=pa[j];
pa[j]=temp;
}
}
}
}
public:
parkinggarage();
void   park_car_in_garage(char*);
void   fetch_car_from_garage(char*);
void   display();
void   display_sort();
};


发表于:2007-05-28 22:42:491楼 得分:50
void   bubble_sort(parkbox   *pa[],int   dimension)
{
int   i,j;
parkbox*   temp;     //用指针
for(i=0;i <dimension;i++)
{
for(j=i+1;j <dimension;j++)
{
if(strcmp(pa[j]-> get_license_plate(),   pa[i]-> get_license_plate())> 0)   //根据字母表排序
{
temp=pa[i];   //交换指针即可
pa[i]=pa[j];
pa[j]=temp;
}
}
}
}
发表于:2007-05-29 01:48:362楼 得分:0
我在display_sort()里面怎么用bubble_sort这个函数可以做到按字母排序,如果没有license_plate则不显示.下面是我的displau_sort()
void   parkinggarage::display_sort()
{
cout < < "---------------------display()sort-------------------- " < <endl;
                  bubble_sort(parkbox,4);//放在这里不对啊运行会引起系统崩溃.到底怎么放这个函数
for(int   i=0;i <boxes;i++)
{
if(parkbox[i]!=null)
{
cout < <parkbox[i]-> get_license_plate() < <endl;
}
else
cout < < " " < <endl;
}
cout < < "--------------------------------- " < <endl;
}


快速检索

最新资讯
热门点击