我想创建一个非二叉树。我想到了一个带有指针指针的这种类型的结构
struct tree{
string name;
int sonc;
tree** son;
};
我为两个大条目崩溃
void insertSon(tree* &a, string n){
if (a->sonc==0){
a->son= new tree*;}
a->son[a->sonc]= new tree;
a->son[a->sonc]->name=n;
a->son[a->sonc]->sonc=0;
a->sonc++;}
但也在取消
void deleteTree(tree* &a){
for (int i=0;i<(a->sonc);++i){
deleteTree(a->son[i]);
}
delete a;}
具有树种群的主要 cpp
tree *tree1;
tree1=new tree;
tree1->name="C:\\TEMP";
tree1->sonc=0;
insertSon(tree1,"C:\\TEMP\\aadvfdbdsbdfgfile1.txt");
insertSon(tree1,"C:\\TEMP\\aadvfdbdsbdfgfile2.txt");
insertSon(tree1,"C:\\TEMP\\FOLDER1");
tree *lastf1=tree1->son[tree1->sonc-1];
insertSon(lastf1,"C:\\TEMP\\FOLDER1\\aadvfdbdsbdfgfile3.txt");
insertSon(lastf1,"C:\\TEMP\\FOLDER1\\aadvfdbdsbdfgfile4.txt");
insertSon(lastf1,"C:\\TEMP\\FOLDER1\\FOLDER2");
tree *lastf2=lastf1->son[lastf1->sonc-1];
for (int i=0;i<100;++i){
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfile5.txt");
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfile6.txt");
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfile7.txt");
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfile8.txt");
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfile9.txt");
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfileA.txt");
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfileB.txt");
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfileC.txt");
insertSon(lastf2,"C:\\TEMP\\FOLDER1\\FOLDER2\\aadvfdbdsbdfgfileD.txt");
}