Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-25-2008, 10:07 AM
Member
 
Join Date: Jun 2008
Posts: 8
tony404 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-25-2008, 10:11 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-25-2008, 10:26 AM
Member
 
Join Date: Jun 2008
Posts: 8
tony404 is on a distinguished road
the result is infinite loop
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-25-2008, 11:00 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Change this,

Code:
while (!root.getList().isEmpty())
as this

Code:
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-25-2008, 11:03 AM
Member
 
Join Date: Jun 2008
Posts: 8
tony404 is on a distinguished road
but then i will not enter to the loop anytime
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-25-2008, 11:12 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-25-2008, 11:51 AM
Member
 
Join Date: Jun 2008
Posts: 8
tony404 is on a distinguished road
i fixed it by adding check if i visit in the node or not
while (!node.getIparamGroupChildren().isEmpty() && !node.isVisited())
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-25-2008, 11:56 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,039
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-25-2008, 12:00 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 282
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
i could not get the recursion in java sivasayanth New To Java 3 04-23-2008 09:08 AM
Help with loop in java trill New To Java 1 08-07-2007 08:36 AM
Recursion in java lenny Advanced Java 1 08-07-2007 07:23 AM
Help, loop with java cachi New To Java 5 08-01-2007 07:03 AM
Enhanced For loop In Java goldhouse Advanced Java 1 05-06-2007 05:26 PM


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