title: DFS return only one element
body: <p>here is DFS algorithm which returns    only one vertex ,instead of  ABCDE</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Stack
  {
  
  private:
       static  const int size=20;
        int *st;
        int top;
  public :
        Stack(){
      st =new int[size];
      top=-1;
  
        }
        ~Stack(){
            delete[] st;
            top=-1;
        }
        void push(int j){
            st[++top]=j;
                }
        int pop(){
            return st[top--];
        }
        int peek(){
  
            return st[top];
  
        }
         bool empthy(){
             return (top==-1);
  
         }
  };
  class Vertex{
  public:
      char  label;
      bool visited;
  public:
      Vertex(){
  
      }
      Vertex(char lab){
          label=lab;
          visited=false;
  
      }
      };
  class Graph{
  private:
  static    const int maxvertex=20;
        Vertex* vertexlist;
        int **adj;
          int nverts;
          Stack *sstack;
  public:
      Graph(){
      vertexlist=new Vertex[maxvertex]; 
      adj=new int*[maxvertex];
       for (int i=0;i&lt;20;i++)
            adj[i]=new int[maxvertex];
       nverts=0;
        for (int i=0;i&lt;maxvertex;i++){
             for (int j=0;j&lt;maxvertex;j++){
                 adj[i][j]=0;
             }
             }
  
           sstack=new Stack();
      }
      void add(char lab){
  
          vertexlist[nverts++] =  Vertex(lab);
      }
      void addedge(int i,int j){
          adj[i][j]=1;
          adj[j][i]=1;
  
  
      }
      void display(int v){
          cout&lt;&lt;vertexlist[v].label&lt;&lt;endl;
  
      }
      int getadjacent(int v){
  
           for (int j=0;j&lt;nverts;j++){
               if (adj[v][j]==1 &amp;&amp; vertexlist[j].visited==1){
                    return j;
               }
  
  
           }
           return -1;
      }
            void dfs(){
                vertexlist[0].visited=true;//mark it
                display(0);
                    sstack-&gt;push(0);
                    while(!sstack-&gt;empthy()){
                        int v=getadjacent(sstack-&gt;peek());
                        if (v==-1){ sstack-&gt;pop();}
                        else{
                            vertexlist[v].visited=true;
                        display(v);
                        sstack-&gt;push(v);
                        }
                    }
  
  
                     for (int j=0;j&lt;nverts;j++){
  
                         vertexlist[j].visited=false;
                     }
  
  
  
            }
  
  
  
  };
  int main(){
  
      Graph *graph=new Graph();
      graph-&gt;add('A');
      graph-&gt;add('B');
      graph-&gt;add('C');
      graph-&gt;add('D');
      graph-&gt;add('E');
      graph-&gt;addedge(0,1);
      graph-&gt;addedge(1,2);
      graph-&gt;addedge(0,3);
      graph-&gt;addedge(3,4);
      cout&lt;&lt;" visits : ";
      graph-&gt;dfs();
      delete []graph;
  
  
  
  
  
  
  
      return 0;
  }
  </code></pre>
  
  <p>it return A,what is wrong in my code?  please help me</p>