Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Iterative from recursive

recursive

  • Please log in to reply
1 reply to this topic

#1 Gerg? Magyar

Gerg? Magyar

    CC Newcomer

  • Member
  • PipPip
  • 22 posts

Posted 10 December 2011 - 10:07 PM


       [COLOR="#800080"][B]public void[/B][/COLOR] bfs(){

		

		Queue<Node> q=[COLOR="#800080"][B]new[/B][/COLOR] LinkedList<Node>();

		q.add([COLOR="#800080"][B]this[/B][/COLOR].[COLOR="#0000FF"]rootNode[/COLOR]);

		printNode([COLOR="#800080"][B]this[/B][/COLOR].[COLOR="#0000FF"]rootNode[/COLOR]);

		[COLOR="#0000FF"]rootNode[/COLOR].[COLOR="#0000FF"]visited[/COLOR]=[COLOR="#800080"][B]true[/B][/COLOR];

		[COLOR="#800080"][B]while[/B][/COLOR](!q.isEmpty())

		{

			Node n=(Node)q.remove();

			Node child=[COLOR="#800080"][B]null[/B][/COLOR];

			[COLOR="#800080"][B]while[/B][/COLOR]((child=getUnvisitedChildNode(n))!=[COLOR="#800080"][B]null[/B][/COLOR])

			{

				child.[COLOR="#0000FF"]visited[/COLOR]=[COLOR="#800080"][B]true[/B][/COLOR];

				printNode(child);

				q.add(child);

				

			}

		}

		clearNodes();

	}


  • 0

#2 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts
  • Programming Language:C, Java, PHP, JavaScript
  • Learning:PHP

Posted 12 December 2011 - 04:46 PM

Is there a question?
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download