Итак, чтобы подвести итог, у меня есть массив указателей, указывающих на объекты класса "bookType", операторы которых были перегружены, и я пытаюсь использовать выбор Sort для сортировки их по количеству в порядке убывания (ie 10 для 1), но после запуска этого кода порядок выглядит случайным.
Выбор сортировки
void selectionSort(bookType *arr[BOOKS], int n){
bookType *temp;
int i, j, minIndex;
for (i = 0; i < n - 1; i++) {
minIndex = i;
for (j = i + 1; j < n; j++)
if (arr[j] > arr[minIndex])
minIndex = j;
if (minIndex != i) {
temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
}
}
прототип bookType:
class bookType{
public:
bookType();
string getTitle() const;
string getAuthor() const;
string getPublisher() const;
string getDateAdded() const;
string getISBN() const;
int getQty() const;
double getWholesale() const;
double getRetail() const;
static int getBookCount();
void setTitle(string title);
void setISBN(string ISBN);
void setDateAdded(string date);
void setAuthor(string author);
void setPublisher(string publisher);
void setQty(int qty);
void setWholesale(double wholesale);
void setRetail(double retail);
static void setBookCount(int count);
bool operator==(const bookType &other);
bool operator!=(const bookType &other);
bool operator<(const bookType &other);
bool operator<=(const bookType &other);
bool operator>=(const bookType &other);
bool operator>(const bookType &other);
void operator=(const bookType &other);
private:
string bookTitle;
string bookAuthor;
string bookPublisher;
string dateAdded;
string bookISBN;
int qtyOnHand;
double bookWholesale;
double bookRetail;
static int bookCount;
};
Код перегрузки
bool bookType::operator==(const bookType &other){
if (getQty() == other.getQty()) return true;
else return false;
}
bool bookType::operator!=(const bookType &other){
if (getQty() != other.getQty()) return true;
else return false;
}
bool bookType::operator<(const bookType &other){
if (getQty() < other.getQty()) return true;
else return false;
}
bool bookType::operator<=(const bookType &other){
if (getQty() <= other.getQty()) return true;
else return false;
}
bool bookType::operator>=(const bookType &other){
if (getQty() >= other.getQty()) return true;
else return false;
}
bool bookType::operator>(const bookType &other){
if (getQty() > other.getQty()) return true;
else return false;
}
void bookType::operator=(const bookType &other){
setTitle(other.getTitle());
setAuthor(other.getAuthor());
setPublisher(other.getPublisher());
setDateAdded(other.getDateAdded());
setISBN(other.getISBN());
setQty(other.getQty());
setWholesale(other.getWholesale());
setRetail(other.getRetail());
}