| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 326 人关注过本帖
标题:请问为什么访问 3 号叶子的路径不能正确返回呢
只看楼主 加入收藏
aa3388650
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-10-30
收藏
 问题点数:0 回复次数:0 
请问为什么访问 3 号叶子的路径不能正确返回呢
#include "stdafx.h"
#include <stdio.h>
#include <string>
using std::string;
struct Node
{
    Node *childl=NULL, *childr=NULL, *father=NULL;
    int data, flag=0;
};


Node* Search(Node *node, int n)
{
    Node *p = NULL;
    if (node->data == n)
    {
        node->flag = 1;
        printf("%d",node->data);
        return node;
    }
    if (node->childl != NULL)
    {
        p = Search(node->childl, n);
        if (p != NULL)
        {
            node->flag++;
            printf("%d", node->data);
            return p;
        }
    }
    if (node->childr != NULL)
    {
        p = Search(node->childr, n);
        if (p != NULL)
        {
            node->flag++;
            printf("%d", node->data);
            return p;
        }
    }
    if (node->childl == NULL&&node->childr == NULL)
    {
        return NULL;
    }
}
void Jump(Node *node, int n[], int i, int j)//j是界限
{
    Node *p = NULL;
    p = Search(node, n[i]);
    if (p != NULL)
    {
        i=i+1;
        if (i <j)
        {
            //printf("%d", p->father->data);
            Jump(p->father, n, i, j);
        }
        else if(i>=j)
        {
            return;
        }
    }
    if (p == NULL)
    {
        if (node->father != NULL)
        {
            //printf("%d", node->data);
            Jump(node->father, n, i, j);
            return;
        }
        if (node->father == NULL)
        {
            return;
        }
    }
}
void Add(Node* p1,Node*p2, int n,Node* target,Node *p3)
{
    target->childl = p1;
    target->childr = p2;
    target->data = n;
    target->father=p3;
}
int _tmain(int argc, _TCHAR* argv[])
{
    int n[2];
    n[0] = 5;
    n[1] = 3;
    Node a, b, c, d, e,f;
    Add(&b,&c,1,&a,NULL);
    Add(&d,NULL, 2, &b,&a);
    Add(&e, &f, 4, &d,&b);
    Add(NULL, NULL, 5, &e,&d);
    Add(NULL, NULL, 6, &f,&d);
    Add(NULL, NULL, 3, &c,&a);
    Node *p = &a;
    Jump(p, n, 0, 2);
    scanf_s("%d",n,1);
    return 0;
}
搜索更多相关主题的帖子: include father return 叶子 
2014-10-30 12:03
快速回复:请问为什么访问 3 号叶子的路径不能正确返回呢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016986 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved