title: Graph representation using Map and Set
body: <pre><code>    using namespace std;
      static int index = 0;
      template&lt;typename T&gt;
      class vertexInfo
      {
          public:
  
                   typename  map&lt; T, int&gt;:: iterator vtxMapLoc;              
                   vertexInfo&lt;T&gt;(int index)
                   {}
                   vertexInfo&lt;T&gt;( typename  map&lt;T, int&gt; :: iterator&amp; iter) : vtxMapLoc{*iter}
                   {}
  
      };
      template &lt;typename T&gt;
      class graph
      {
          private:
  
                  typename  map&lt; T, int &gt; :: iterator iter;
                  map &lt;T,int&gt; vtxMap;
                  vector&lt;vertexInfo&lt;T&gt; &gt; vInfo;  
          public:
                  void addEdge( graph&lt;T&gt;&amp; , const T&amp; , const T&amp;, int );
                  void show(graph&lt;T&gt;&amp; );
                  void show_map_element( graph&lt;T&gt;&amp; );
  
  
  
      };
      int main()
      {
          graph&lt;char&gt; g;
          g.addEdge(g,'A','B', 2);
          g.addEdge(g,'A','C', 3);
          g.addEdge(g,'B','D', 5);
          g.addEdge(g,'C','D', 1);
          g.addEdge(g,'B','C', 7);
          g.addEdge(g,'D','E', 4);
          g.show(g);
          g.show_map_element(g);
          return 0;
      }
  
      template &lt;typename T&gt;
      void graph&lt;T&gt; :: addEdge ( graph&lt;T&gt; &amp; g, const T&amp; v1 , const T&amp; v2, int w)
      {
          pair &lt;map &lt;char, int&gt; :: iterator, bool&gt; ret ;
  
           ret = g.vtxMap.insert(pair &lt;char, int &gt;( v1, index));
  
           if( ret.second)
           {
  
              g.vInfo.push_back(index);
              (g.vInfo[index].vtxMapLoc) = vtxMap.find(index);   
              index++;
  
            }
  
           ret = g.vtxMap.insert(pair &lt;char, int &gt;(v2 , index));
  
           if( ret.second)
           {
  
              g.vInfo.push_back(index);
              (g.vInfo[index].vtxMapLoc) = vtxMap.find(index);    
              index++;
            }
  
         }
   }
  template&lt;typename T&gt;
  void graph&lt;T&gt; :: show( graph&lt;T&gt;&amp; g)
  {
      for( g.iter = g.vtxMap.begin(); g.iter != g.vtxMap.end(); g.iter++)
           {
               cout&lt;&lt; (*(g.iter)).first &lt;&lt;" - &gt;" &lt;&lt; (*(g.iter)).second &lt;&lt;endl;
           }
  
  }
  template&lt;typename T&gt;
  void graph&lt;T&gt; :: show_map_element( graph&lt;T&gt;&amp; g)
  {
  
     cout&lt;&lt; (*g.vInfo[2].vtxMapLoc).first&lt;&lt;endl;
     cout&lt;&lt; (*g.vInfo[3].vtxMapLoc).second&lt;&lt;endl;
     cout&lt;&lt; (*g.vInfo[4].vtxMapLoc).first&lt;&lt;endl;
  }
  
  
  Output :    
            A -&gt; 0    
            B -&gt; 1   
            C -&gt; 2   
            D -&gt; 3    
            E -&gt; 4
                 ( nothing printed )
            0    
                 ( nothing printed )   
  </code></pre>
  
  <p>I am having doubt about output ( last 3 lines )<br>
  It should have been    </p>
  
  <pre><code>C    
  3     
  E
  </code></pre>
  
  <p>because<br>
  <code>(*g.vInfo[2].vtxMapLoc)</code> points to ( C , 2 ) and it's first is C<br>
  <code>(*g.vInfo[3].vtxMapLoc)</code> points to ( D , 3 ) and it's second is 3<br>
  <code>(*g.vInfo[4].vtxMapLoc)</code> points to ( E , 4 ) and it's first is E   </p>
  
  <p>It seems that vector <code>vInfo</code> is not properly pointing to map <code>vtxMap</code><br>
  <code>(*g.vInfo[index].vtxMapLoc) = vtxMap.find(index)</code>   is this pointing correct ?? </p>