0
私はこのコードhttps://rosettacode.org/wiki/AVL_tree#C.2B.2BをAVLツリーの基礎として使用しています。デフォルトでは、この例では整数が使用されていますが、文字列を格納する必要があります。そこで、コードを変更して、主にルート公開とデバッグを行いました。avlツリーの検索を実装しようとしています
22 /* AVL tree */
23 template <class T>
24 class AVLtree {
25 public:
26 AVLtree(void);
27 ~AVLtree(void);
28 bool insert(T key);
29 void deleteKey(const T key);
30 void printBalance();
31 AVLnode<T> *root;
32
33 private:
34
35 AVLnode<T>* rotateLeft (AVLnode<T> *a);
36 AVLnode<T>* rotateRight (AVLnode<T> *a);
37 AVLnode<T>* rotateLeftThenRight (AVLnode<T> *n);
38 AVLnode<T>* rotateRightThenLeft (AVLnode<T> *n);
39 void rebalance (AVLnode<T> *n);
40 int height (AVLnode<T> *n);
41 void setBalance (AVLnode<T> *n);
42 void printBalance (AVLnode<T> *n);
43 void clearNode (AVLnode<T> *n);
44 };
..................................
247 int main(void)
248 {
249 AVLtree<std::string> t;
250
251 std::cout << "Inserting integer values 1 to 10" << std::endl;
252 for (int i = 1; i <= 10; ++i)
253 t.insert(i+" ");
254
255 std::cout << "Printing balance: ";
256 t.printBalance();
257 std::cout << t.root->key + "\n";
258 std::cout << t.root->left->key + "\n";
259 std::cout << t.root->left->right->key + "\n";
260 std::cout << t.root->key;
261
262 }
問題が出て印刷した結果が
Inserting integer values 1 to 10
Printing balance: 1 0 -1 0 0 1 0 0 1 0
ing balance:
Printing balance:
g balance:
ing balance:
と私は理由は分からないということですが。
ありがとうto_stringを使用してエラーが発生しましたが、回避するのではなく、修正することに集中することにしました。 – dlrdlrdlr