二叉树的中序遍历

二叉树的遍历方式 忘得差不多了 .......应该在记一下

 

歌词不是重点  重点是 知识(装一下逼)   下面附上代码  和  二叉树的 遍历 顺序 

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
typedef struct
{
    int x, y;
}node;
node num[20];
void fun(int n)
{
    if(n == -1)
        return;
    fun(num[n].x);
    printf("%d\n", n);
    fun(num[n].y);
}

int main(){
    int chioce, i, n, m ,f, x, y;
    scanf("%d", &chioce);
    while(chioce--)
    {
        scanf("%d", &n);
        for(i = 0; i < 14; i++)
            num[i].x = num[i].y = 0;

        while(n--)
        {
            scanf("%d%d%d", &f, &x, &y);
            num[f].x = x;
            num[f].y = y;
        }
        scanf("%d", &m);
        while(m--)
        {
            scanf("%d%d", &x, &y);
        }
        fun(0);
        printf("\n");
    }
    return 0;
}

 

posted @ 2016-03-18 20:19  X-POWER  阅读(374)  评论(0编辑  收藏  举报