Thread: breadth-first-search

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    13

    breadth-first-search

    How the breadth-first-search run? Can anyone shows me the source code?

  2. #2
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    ah, i might knew that you are getting your TARC assignment right ???
    ok ok ... here's the clue...

    try to look at the question and the example that given, see how the searching point look at, and how it's move.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Use a queue (instead of a stack or direct child manipulation)
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    27
    it is something like this, but of course without the object stuff. This should at least give you the basic idea then you can write it in plan C.

    Code:
    void printBFS(Node root)
    {
    
    	Queue Q = new Queue();
    
    	if(roo != null)
    	{
    		Q.enq(root);
    	}
    
    	while(!Q.isEmpty())
    	{
    
    		Node cur = Q.deq();
    
    		printf(cur);
    
    		if(cur.left != null)
    		{
    			Q.enq(cur.left);
    		}
    		
    		if(cur.right != null)
    		{	
    			Q.enq(cur.right);
    		}
    	}
    }
    Last edited by samps005; 12-08-2002 at 11:38 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shortest Path Maze Solver (Breadth Search Help)
    By Raskalnikov in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 07:41 PM
  2. Using Breadth First Search
    By neandrake in forum C++ Programming
    Replies: 4
    Last Post: 05-06-2005, 05:13 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM