Jump to content

Iterative from recursive

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Gerg? Magyar

Gerg? Magyar

    Newbie

  • Members
  • PipPip
  • 22 posts

       [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();

	}



#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Is there a question?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users