0

每当我在我的 B+ 树中插入一个新元素时,它似乎会在插入函数开始之前用要插入的数据点重写每个数据点。我发现的唯一可能原因是我的 bPLus 对象似乎无法访问每个节点中保存的 Professor 结构。例如,如果我在调试器中,所有教授值都是空的。另一方面,钥匙(cle)可以工作并且可以访问。可能与指针有关?

当我不使用按键时,如果我从 main 调用某些函数,我会得到“读取字符串字符时出错”,而其他函数会起作用。如果从类内的工作函数调用这些相同的函数也将起作用。我有一种感觉,这些问题都是相关的。

我已经包括了所有可能涉及的内容,我不知所措。

struct Professeur {
    string ID;
    string nom;
    string dept;
    string salaire;
};

struct Noeud {
    Professeur *valeur[3];
    string cle[3];
    Noeud *enfant[4];
    Noeud *parent;
    Noeud *suivant;
    bool isLeaf;

    Noeud(){
        for (int i = 0; i < 3; i++) {
            valeur[i] = NULL;
            enfant[i] = NULL;
            cle[i] = "vide";
        }
        isLeaf = 0;
        parent = NULL;
        suivant = NULL;
        enfant[3] = NULL;
    }
};

class bPlus {
private:
    Noeud* racine;
public:
    bPlus() {
        racine = new Noeud;
        racine->isLeaf = 1;
    }

    void inserer(Professeur x) {
        if (findValue(x.nom)) {
            return;
        }
        if (racine->isLeaf) {
            //do the insertion
        }

        else {
            //find leaf, do insertion
        }
    }
int main() {
    Professeur profs[12];

    //gather data from text file

    for (int i = 0; i < 12; i++) {
        profs[i].ID = ID[i];
        profs[i].nom = nom[i];
        profs[i].dept = dept[i];
        profs[i].salaire = salaire[i];
    }

    bPlus arbre;
    for (int i = 0; i < 3; i++) {
        arbre.inserer(profs[i]);
    }

    return 0;
}
4

0 回答 0