代码给出ASCII数字而不是字符

时间:2015-05-21 07:54:59

标签: c++ char ascii red-black-tree

此代码是RedBlack Tree程序的一部分,该程序应该接收“ADSOMERT”并将其字符排序为Inorder格式“A D E M O R S T”。它完成了这项工作,但每个字符的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();
}

insert和rb_insert fucntions:

void Tree::insert(int x)
{
    ...
}

void Tree::rb_insert(Node *& node, Node *&parent, int x, bool sw)
{
    ...
}

inorder和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);
    }
}

Node和Tree的类依赖项:

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;
}

1 个答案:

答案 0 :(得分:1)

template <class T>
class Node{
public:
    Node(int data = 0);
    bool red;
    T item;
    ....
};

您正在输出node-&gt;项,它是一个int。如果你想输出&#34; A D E M O R S T&#34;

,应该是一个字符
.Where("@0.Contains(jobId.ToString()) or title.Contains(@0)", "23")

像这样的东西