我無法打印我的二進制樹的順序,預訂和後序。我在讀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;
}
「但是,現在我正在從txt文件中讀取數據,按順序排列,預訂單和後期訂單都打印出從txt文件讀入的內容。」 - 聽起來很正確。有什麼問題? – Shoe
如果我的文件讀取'abcd',我的inorder,preorder和postorder全部打印出'abcd'。但是,後期應打印出反向'dcba' – user3335367