如何检索函数中的指针结构

时间:2017-07-16 08:27:29

标签: c++ data-structures binary-tree

我有这样的结构:

struct ClientNode
{
string name;
int flightnumber;
int clientno;
ClientNode * right;
ClientNode* left;
};

然后我声明了这个结构的指针:

ClientNode* root = new ClientNode;

在一个函数中我已经为root初始化了clientno:

root->clientno = 11;

然后我想将root作为参数发送到函数:

ClientNode newnode;
root = Insert_to_AVL_Tree(&newnode, root);

这是我的Insert_to_AVL_Tree:

ClientNode* clientclass::Insert_to_AVL_Tree(ClientNode* Node, ClientNode* root) 

这是错误发生的地方,我已经初始化了root-> clientno但是当我将它传递给另一个函数时它似乎发生了变化,因此它无法与if,also node->中的值进行比较。 clientno具有从我的代码的另一部分中的文件中读取的正确值:

if (Node->clientno < root->clientno)
root->left = Insert_to_AVL_Tree(Node, root->left);

在另一个函数中获取root-&gt; clientno值的正确方法是什么? here is the value shown for root->clientno

here is the value for node->cleintno

1 个答案:

答案 0 :(得分:-2)

为了将Pointer传递给函数,我使用的最好方法是双指针

void clear(int **p)
{
   *p = 0;
}

int main()
{
   int* p;
   clear(&p);
   return 0;
}