我一直在解決這個了一會兒,環顧四周,但我不知道我在做什麼錯'。'之前的預期主表達式令牌
錯誤:
錯誤:「」之前預期基本表達式令牌
被彈出了大部分的addElement方法 其中BinaryNode.variable而言內部的代碼,但我完全失去了在這裏做什麼
#include <cstdlib>
#include "BinarySearchTree.h"
using namespace std;
template <typename Comparable>
BinarySearchTree<Comparable>::BinarySearchTree(const Comparable & theElement, BinarySearchTree<Comparable> *leftTree,
BinarySearchTree<Comparable> *rightTree) : BinaryNode(theElement,leftTree,rightTree) {
}
template <typename Comparable>
void BinarySearchTree<Comparable>::addElement(Comparable newElement) {
if(newElement < BinaryNode.element) {
if(BinaryNode.left == NULL) {
BinaryNode.left = BinarySearchTree(newElement, NULL, NULL);
BinaryNode.right.root = BinaryNode;
} else {
BinaryNode.left.addElement(newElement);
}
} else if (newElement > BinaryNode.element) {
if(BinaryNode.right == NULL) {
BinaryNode.right = BinarySearchTree(newElement, NULL, NULL);
BinaryNode.right.root = this;
} else {
BinaryNode.right.addElement(newElement);
}
}
而這裏的heade對於BinarySearchTree
#include <vector>
using namespace std;
template<typename Comparable>
class BinarySearchTree {
public:
BinarySearchTree(const Comparable & theElement, BinarySearchTree<Comparable> * leftTree,
BinarySearchTree<Comparable> * rightTree);
void addElement(Comparable newElement);
void removeElement(Comparable newElement);
BinarySearchTree<Comparable> * findElement(Comparable newElement);
bool isEmpty();
BinarySearchTree & operator=(const BinarySearchTree &tree);
vector<BinarySearchTree> preOrder(vector<BinarySearchTree> * list);
vector<BinarySearchTree> inOrder();
vector<BinarySearchTree> postOrder();
private:
struct BinaryNode {
Comparable element;
BinarySearchTree<Comparable> *left;
BinarySearchTree<Comparable> *right;
BinaryNode(const Comparable & theElement, BinarySearchTree<Comparable> *leftTree,
BinarySearchTree<Comparable> *rightTree) : element(theElement), left(leftTree), right(rightTree){}
};
BinaryNode *root;
};
請指出錯誤發生在哪一行。 – Brian
這是代碼爲 – user3317055