#include<iostream> #include"Stack.hpp" #include<string> #include"BNode.hpp" #include"BinaryTree.hpp" using namespace std; int main() { const char* p = "A(B(C,D(,E)),)"; BinaryTree<char> *tree = new BinaryTree<char>(p); cout << "后序遍历非递归:"; tree->PosOrder(); cout << endl; cout << "后序遍历递归:"; tree->PosOrderRe(tree->root); cout << endl; cout << "先序遍历非递归:"; tree->PreOrderNotRe(); cout << endl; cout << "中序遍历非递归:"; tree->InOrder(); cout << endl; cout << "B的兄弟:"; tree->ShowAncestor('B'); cout << endl; cout << "E的兄弟:"; tree->ShowAncestor('E'); cout << endl; cout << "C的长辈:"; tree->FindAllAncestor('C'); cout << endl; cout << "E的长辈:"; tree->FindAllAncestor('E'); system("pause"); return 0; }
时间: 2023-10-30 21:27:25 浏览: 103
wavecar.hpp:一个C ++库,用于从VASP中读取和操作WAVECAR文件
以下是将C++语言的代码翻译成Java语言的代码:
```java
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
String p = "A(B(C,D(,E)),)";
BinaryTree<Character> tree = new BinaryTree<Character>(p);
System.out.print("后序遍历非递归:");
tree.PosOrder();
System.out.println();
System.out.print("后序遍历递归:");
tree.PosOrderRe(tree.root);
System.out.println();
System.out.print("先序遍历非递归:");
tree.PreOrderNotRe();
System.out.println();
System.out.print("中序遍历非递归:");
tree.InOrder();
System.out.println();
System.out.print("B的兄弟:");
tree.ShowAncestor('B');
System.out.println();
System.out.print("E的兄弟:");
tree.ShowAncestor('E');
System.out.println();
System.out.print("C的长辈:");
tree.FindAllAncestor('C');
System.out.println();
System.out.print("E的长辈:");
tree.FindAllAncestor('E');
}
}
```
阅读全文