无法在输出文件中打印R树

时间:2017-04-14 06:36:44

标签: c++

在给定input.txt的情况下,无法使用打印功能打印r树。 无法获得任何输出。 输入是 - 加2 3 1 2 1 加7 10 1 2 2 加1 2 5 8 3 打印

ifstream 
inputFile("C:/Users/YOLO/Documents/NetBeansProjects/rtree_header/input.txt"); 
  ofstream outFile; outFile.open("C:/Users/YOLO/Documents/NetBeansProjects/rtree_header/output.txt");

if (operation == "print") {
        myRtree.PrintRtree(outFile);
        continue;
    }

//我想在输出文件中打印树结构

void Rtree::PrintRtree(ofstream &outputStream) {
if (outputStream.is_open() == true) {
    if (root->childs == NULL) {
        outputStream << "tree is empty" << endl;
        return;
    }
    _PrintRtree(root, 0, outputStream);
    outputStream << endl;
}
else
    cout << "output stream error" << endl;
}

//我想打印包含根,节点和叶子的树结构

void Rtree::_PrintRtree(Node* curNode, int level, ofstream &outputStream) {
for (int i = 0; i < level; i++) {
    outputStream << "\t";
}

switch (curNode->type) {
case NODE:
    outputStream << "NODE";
    break;
case LEAF:
    outputStream << "LEAF";
    break;
case OBJECT:
    outputStream << "OBJECT";
    break;
}
outputStream << " x1=" << curNode->covering.x1
             << " x2=" << curNode->covering.x2
             << " y1=" << curNode->covering.y1
             << " y2=" << curNode->covering.y2;

if (curNode->type == OBJECT)
    outputStream << " data=" << curNode->data << endl;
else {
    outputStream << endl;
    for (int i = 0; i < curNode->objCount; i++) {
        _PrintRtree(curNode->childs[i], level + 1, outputStream);
    }
}
}

0 个答案:

没有答案