按顺序打印时遇到问题,二叉树的后顺序等
Trouble printing in order, post order ect for a binary tree
我在打印我的二叉树的顺序、预序和后序时遇到问题。当我从 cin 阅读时,我让它工作。但是,现在我正在从 txt 文件中读取,我的顺序、预购和后顺序都打印出从 txt 文件中读入的内容。我已经提供了我认为问题存在的代码,如果您需要查看我的其余代码,请发表评论。
我的代码:
int main()
{
vector <BinaryTree <string> > BT;
int iteration = 0;
string line;
ifstream myfile("input.txt");
if (myfile.is_open())
{
while(getline (myfile, line))
{
BinaryTree <string> temptree;
BT.push_back(temptree);
BT[iteration].InsertData(line);
cout << "Preorder: ";
BT[iteration].PrintPreorder();
cout << endl;
cout << "Inorder: ";
BT[iteration].PrintInorder();
cout << endl;
cout << "Postorder: ";
BT[iteration].PrintPostorder();
cout << endl;
cout << "Reverse Inorder: ";
BT[iteration].PrintReverseInorder();
cout << endl;
BT[iteration].PrintPrintTree();
cout << endl;
iteration++;
}
myfile.close();
}
return 0;
}
您的输入是否应该一次是一个字符?当您想要一次接受一个字符时,看起来您正在接受文本行,这可以解释您的输出("abcd"是一个节点,您的根)。
相关文章:
- 从父数组测试用例构造二叉树失败
- 打印时有二叉树问题.用户输入不打印任何内容
- 试图找到二叉树的深度
- 二叉树级别顺序遍历在leetcode中
- 二叉树级别顺序插入 c++
- 使用二叉树的关卡顺序概念的垂直顺序遍历
- 二叉树级别顺序遍历 LeetCode
- 如何修复关卡顺序遍历问题(二叉树)的无限循环错误
- 二叉树顺序遍历在C++
- 按顺序打印时遇到问题,二叉树的后顺序等
- 二叉树顺序遍历错误:没有用于调用的匹配函数
- 使用递归的顺序二叉树遍历与使用堆栈的优缺点
- 使用级别顺序遍历将节点插入二叉树
- 二叉树顺序遍历导致堆栈溢出
- 无法使用非递归顺序方法遍历二叉树
- 线程内二叉树的插入或顺序遍历有什么问题
- 按字母顺序排列的二叉树
- 二叉树:迭代顺序打印
- 在TXT文件中按顺序写入二叉树
- c++递归打印二叉树的顺序问题