代码给出 ASCII 数字而不是字符
code gives out ASCII numbers instead of characters
此代码是应该接收 "ADSOMERT" 并将其字符排序为有序形式 "A D E M O R S T" 的 RedBlack Tree 程序的一部分。它完成了这项工作,但每个字符的 ASCII 数字为“65 68 69 77 79 82 83 84”。
主要功能:
int main()
{
Tree char_tree = Tree();
cout << "Eingabe: ADSOMERT" << endl;
char_tree.insert('A');
char_tree.insert('D');
char_tree.insert('S');
char_tree.insert('O');
char_tree.insert('M');
char_tree.insert('E');
char_tree.insert('R');
char_tree.insert('T');
cout << "ADSOMERT in In-Order" << endl;
char_tree.print_inorder();
}
插入和rb_insert函数:
void Tree::insert(int x)
{
...
}
void Tree::rb_insert(Node *& node, Node *&parent, int x, bool sw)
{
...
}
顺序和print_inorder函数:
void Tree::print_inorder()
{
inorder(head->right);
cout << endl;
}
void Tree::inorder(Knote* node)
{
if (node != nullptr)
{
inorder(node->left);
cout << node->item << " ";
inorder(node->right);
}
}
class 节点和树的依赖项:
Node.h
class Node {
public:
Node(int data = 0);
bool red;
int item;
Node *left;
Node *right;
Node *parent;
};
Node.cpp
Node::Node(int data)
{
this->item = data;
parent = nullptr;
left = nullptr;
right = nullptr;
red = true;
}
void Tree::inorder(Knote* node)
{
if (node != nullptr)
{
inorder(node->left);
cout << node->item << " ";
inorder(node->right);
}
}
class Node {
public:
Node(int data = 0);
bool red;
int item;
Node *left;
Node *right;
Node *parent;
};
你输出的是node->item,它是一个int。如果你想输出 "A D E M O R S T"
应该是一个字符
template <class T>
class Node{
public:
Node(int data = 0);
bool red;
T item;
....
};
像这样
此代码是应该接收 "ADSOMERT" 并将其字符排序为有序形式 "A D E M O R S T" 的 RedBlack Tree 程序的一部分。它完成了这项工作,但每个字符的 ASCII 数字为“65 68 69 77 79 82 83 84”。
主要功能:
int main()
{
Tree char_tree = Tree();
cout << "Eingabe: ADSOMERT" << endl;
char_tree.insert('A');
char_tree.insert('D');
char_tree.insert('S');
char_tree.insert('O');
char_tree.insert('M');
char_tree.insert('E');
char_tree.insert('R');
char_tree.insert('T');
cout << "ADSOMERT in In-Order" << endl;
char_tree.print_inorder();
}
插入和rb_insert函数:
void Tree::insert(int x)
{
...
}
void Tree::rb_insert(Node *& node, Node *&parent, int x, bool sw)
{
...
}
顺序和print_inorder函数:
void Tree::print_inorder()
{
inorder(head->right);
cout << endl;
}
void Tree::inorder(Knote* node)
{
if (node != nullptr)
{
inorder(node->left);
cout << node->item << " ";
inorder(node->right);
}
}
class 节点和树的依赖项:
Node.h
class Node {
public:
Node(int data = 0);
bool red;
int item;
Node *left;
Node *right;
Node *parent;
};
Node.cpp
Node::Node(int data)
{
this->item = data;
parent = nullptr;
left = nullptr;
right = nullptr;
red = true;
}
void Tree::inorder(Knote* node)
{
if (node != nullptr)
{
inorder(node->left);
cout << node->item << " ";
inorder(node->right);
}
}
class Node {
public:
Node(int data = 0);
bool red;
int item;
Node *left;
Node *right;
Node *parent;
};
你输出的是node->item,它是一个int。如果你想输出 "A D E M O R S T"
应该是一个字符template <class T>
class Node{
public:
Node(int data = 0);
bool red;
T item;
....
};
像这样