树的非递归前序遍历

来源:互联网 发布:asp读取excel数据 编辑:程序博客网 时间:2024/06/05 01:19

这里写图片描述
看图学习

void FrontPrint(BiNode *root, PRINT print){    if (root == NULL)        return;    stack<BiNode*> s;    while (!s.empty()||root)    {        while (root != NULL)        {            print(root->data);            s.push(root);            root = root->lChild;        }        if(!s.empty()){            BiNode *node=s.top();            s.pop();            root = node->rChild;        }    }}
0 0
原创粉丝点击