Şu anda beni kolayca ikili arama ağacının içindeki verilerin türünü değiştirmek için izin şablonlar kullanılarak, bir ikili arama ağacı kurulum var. Şu anda sorun ağacında saklanmasına verileri içeren studentRecord sınıfını aşırı yaşıyorum. Benim BST düzgün içerikleri birine dayalı iki nesne karşılaştırmak böylece ben (bu durumda, öğrenci kimliği), bu sınıfın içinde karşılaştırma operatörlerini aşırı gerekir. Ancak, studentRecord içinde operatörleri aşırı rağmen, doğru karşılaştırmalar hala gerçekleşmiyor.
Detaylar aşağıda:
Şu anda, BST nesne studentTree türünden bağımsız olarak, yaratılmıştır
bst<studentRecord *> studentTree;
studentRecord şu sınıftır:
// studentRecord class
class studentRecord{
public:
// standard constructors and destructors
studentRecord(int studentID, string lastName, string firstName, string academicYear){ // constructor
this->studentID=studentID;
this->lastName=lastName;
this->firstName=firstName;
this->academicYear=academicYear;
}
friend bool operator > (studentRecord &record1, studentRecord &record2){
if (record1.studentID > record2.studentID)
cout << Greater! << endl;
else
cout << Less then! << endl;
return (record1.studentID > record2.studentID);
}
private:
// student information
string studentID;
string lastName;
string firstName;
string academicYear;
};
yeni öğeler benim BST eklenir zaman, birbirleriyle karşılaştırılmalıdır. Bu nedenle, bu karşılaştırma işlemi gerçekleştiğinde, studentIDs karşılaştırıldığında, böylece studentRecord sınıfı aşırı istediğini (aksi takdirde, geçersiz bir karşılaştırma yapılmaktadır).
Ancak, benim ekleme fonksiyonu asla benim aşırı karşılaştırma işlevlerini kullanır. Bunun yerine, BST içinde geçersiz sıralamaya sonuçlanan iki nesneleri başka bir yol karşılaştırarak gibi görünüyor. Benim insert fonksiyonunun Bölüm altındadır - toInsert ve nodePtr-> veriler hem sebebiyle şablon süreç husul, tip studentRecord olması gerektiğini not etmek önemlidir.
// insert (private recursive function)
template<typename bstType>
void bst<bstType>::insert(bstType & toInsert, bstNodePtr & nodePtr){
// check to see if the nodePtr is null, if it is, we've found our insertion point (base case)
if (nodePtr == NULL){
nodePtr = new bst<bstType>::bstNode(toInsert);
}
// else, we are going to need to keep searching (recursive case)
// we perform this operation recursively, to allow for rotations (if AVL tree support is enabled)
// check for left
else if (toInsert < (nodePtr->data)){ // go to the left (item is smaller)
// perform recursive insert
insert(toInsert,nodePtr->left);
// AVL tree sorting
if(getNodeHeight(nodePtr->left) - getNodeHeight(nodePtr->right) == 2 && AVLEnabled)
if (toInsert < nodePtr->left->data)
rotateWithLeftChild(nodePtr);
else
doubleRotateWithLeftChild(nodePtr);
}
Ayrıca, burada BST sınıfı Definition bir kısmıdır
// BST class w/ templates
template <typename bstType>
class bst{
private: // private data members
// BST node structure (inline class)
class bstNode{
public: // public components in bstNode
// data members
bstType data;
bstNode* left;
bstNode* right;
// balancing information
int height;
// constructor
bstNode(bstType item){
left = NULL;
right = NULL;
data = item;
height = 0;
}
// destructor
// no special destructor is required for bstNode
};
// BST node pointer
typedef bstNode* bstNodePtr;
public: // public functions.....
Bu neyin sebep olabileceğini herhangi bir fikir? Yanlış sınıf veya yanlış işlev aşırı muyum? Herhangi bir yardım takdir - Bu kadar çok farklı şeyler aynı anda gerçekleştiğini beri kaybolmadan gibi görünüyor.













