Topic: 树的遍历问题

  Print this page

1.树的遍历问题 Copy to clipboard
Posted by: pinkpig1982
Posted on: 2005-12-05 17:12

这几天一直在烦一个很烦的问题
有这样一个图,图在附件

根据这个图我用这样一个数组存储节点间的关系:
int[][] tempList = new int[13][2];
tempList[0] = {1,3};
tempList[1] = {3,6};
tempList[2] = {3,7};
tempList[3] = {3,8};
tempList[4] = {6,9};
tempList[5] = {6,10};
tempList[6] = {7,11};
tempList[7] = {7,12};
tempList[8] = {8,2};
tempList[9] = {9,2};
tempList[10] = {10,2};
tempList[11] = {11,2};
tempList[12] = {12,2};

希望根据这个数组print出下面的东西:
1();
int value3 = 3();
if(value3 ...)
{
int value6 = 6();
if(value6 ...)
{
9();
2();
}
else if(value6 ...)
{
10();
2();
}
}
else if(value3 ...)
{
int value7 = 7();
if(value7 ...)
{
11();
2();
}
else if(value7 ...)
{
12();
2();
}

}
else if(3 ...)
{
8();
}

这个图和print出来的东西只是举例,其它不同形状的图也要能按照这个规则print出来
我真是做了好久都做不出来!所以请各位帮个忙吧,小女子在这里谢过了!

abc.gif (167.8k)

2.Re:树的遍历问题 [Re: pinkpig1982] Copy to clipboard
Posted by: justforfun
Posted on: 2005-12-06 06:46

You code is not even compilable.
How may I help you?

3.Re:树的遍历问题 [Re: pinkpig1982] Copy to clipboard
Posted by: ftang
Posted on: 2005-12-09 06:23

I am very confused what you try to "print" ( you don't even print call in sample code)....about 树的遍历 there are very common algorithms...from left or right, up to down, the currently competition is which one is fastest...and also from the pic I saw here...it is more like graphic problem not tree. give describe clearly...I might help you out...

4.Re:树的遍历问题 [Re: pinkpig1982] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-12-09 09:10

Graph, not Graphic

They are totally different things.

5.Re:树的遍历问题 [Re: pinkpig1982] Copy to clipboard
Posted by: ftang
Posted on: 2005-12-09 23:39

hehe...thks correct me though...I am not good at words


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923