|
|
|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

06-25-2008, 10:07 AM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 8
|
|
|
java recursion infinite loop
Hi i need to go over tree in java and print all the nodes
tempdata is the node structe:
class DataType {
String name;
LinkList DataType ;
getList{
return DataType
}
}
public void printTree(DataType node) {
DataType root = node;
while (!root.getList().isEmpty())
{
LinkedList list1 = root.getlinklist();
Iterator i = list1.iterator();
while (i.hasNext()) {
dataType tempDataType= (dataType)i.next();
printTree(tempDataType);
System.out.println( tempDataType.getName());
}
}
}
this soulution is infinite i get infinte loop
can any one suggent soultion to this probelm or any easy way to go over the tree and printed it. (it;s tree of tree)
10x.
|
|

06-25-2008, 10:11 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
|
Is this working at all?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-25-2008, 10:26 AM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 8
|
|
|
the result is infinite loop
|
|

06-25-2008, 11:00 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
Change this,
while (!root.getList().isEmpty())
as this
while (root.getList().isEmpty())
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-25-2008, 11:03 AM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 8
|
|
|
but then i will not enter to the loop anytime
|
|

06-25-2008, 11:12 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
|
Ya, that's what I want to know. Just after that try to find the number of elements have in the list. If there is specific number of elements then something going wrong with the rest of the code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-25-2008, 11:51 AM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 8
|
|
|
i fixed it by adding check if i visit in the node or not
while (!node.getIparamGroupChildren().isEmpty() && !node.isVisited())
|
|

06-25-2008, 11:56 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
|
|
|
It's much better. Everything is fine now? In such a case start from the most outer loop. Check the possibilities it can have, and move to inner loops. Then you can find the firing condition for infinite loop.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

06-25-2008, 12:00 PM
|
 |
Senior Member
|
|
Join Date: May 2008
Posts: 282
|
|
|
Hello tony,
Can u tell me which tree nodes r u trying to print? Is it a JTree,binary tree or any other such tree.
__________________
To finish sooner, take your own time....
Nivedithaaaa
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
All times are GMT +3. The time now is 02:22 PM.
|
|
VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org