Hello,
it would be nice if somebody can help me.
the problem seems to be trivial, but I don't see my mistake.
There is class colony- an array of pointers to objects named bunny. The bunny has the integer method: bunny.age.
class bunny
{
public:
int age,s;
char *sex,*name,*color,*mtn;
bool mutant;
bunny();
void show_bunny();
};
void bunny::show_bunny()
{
cout<<name<<": " <<sex<<", "<<age<<" year(s), "<<color<<". "<<mtn<<"\n";
}
class class_colony
{
private:
bunny *colony[colony_size];
int population;//current population of the colony
public:
class_colony(int start_population);
void show_colony(); // Prints all the colony members
};
Within the method show_colony(), I try to sort bunnies by age and print them consequently:
Your sorting algorithm looks like it won't work. At best, it might change around a few bunnies.
Looks like you've tried to implement a bubble sort, but you've missed a key point. With this sort, you have to repeat the sort over the entire array over and over until you find there are no more changes being made.