DFS:Depth First Search Program in Java to Search a Tree

Discussion in 'Programming' started by rainbow9, Aug 18, 2011.

  1. #1
    DFS:Depth First search is an algorithm that is used to span a tree and find the required elements of the tree.The Algorithm process Depth wise or level wise moving form top to bottom levels of the tree.DFS Requires a Stack to Implemented to push and pop the elemenst during treversal a Stack can be implemented by the following Code
    
    class stack      {       
    int a[]=new int[20],top=0;
           void push(int p)       {        a[top]=p;        top++;       
    }
           int pop()
           { 
           int h;        top--;        h=a[top];        return h;
           }      
    }
    Code (markup):
    The Complete Source Program to Implement DFS can be found at www.codeuniverse.tk
     
    rainbow9, Aug 18, 2011 IP