Graph representation using Map and set

When I will add edge( A, B, 1). It should be stored as ( A , 0) , ( B , 1 ) in map ( T, key ) vtxMap. when I will add edge ( B , C , 6 ), it should be stored as ( C , 2 ) ( only C bcoz , B has already stored. )

Now , vInfo is vector , in which key of map(T, key)vtxMap has stored. So it's field will be vInfo[0] = 0 , vInfo[1] = 1 , vInfo[2] = 2 etc...

Now this each vInfo field is pointing to some member functions like edges(), inDegree() , outDegree(), distance() , vtxMapLoc ( it is iterator) It means vInfo[0] will point to above functions then vInfo[1] will point all above functions.

So when I want to access these functions I will access like vInfo[0].inDegree() or vInfo[1].inDegree()

In this when I will access vInfo[0].vtxMapLoc it will point to map(T,key) vtxmap's 1st entry i.e ( A, 0 )

vInfo[1].vtxMapLoc it will point to map(T,key) vtxMap's 2nd entry i.e. ( B, 1)

I problem :
For that following code has written but i am not able to do mapping of vInfo[0].vtxMapLoc to ( A, 0 ) How to do that ?? I tried this way : (*g.vInfo[index].vtxMapLoc) = vtxMap[index]; but got error as " no match for operator = "

II problem
vInfo[i].edges() stores destination vertex of edge with weight. It means for edge ( A , B , 3) it will store 1 ( for B bcoz its Index in vInfo is 1 ) with wight 3. i.e. ( 1, 3 )

for edge ( B , c , 6) it will store 2 ( C's index in vInfo is 2 ) with 6 i.e. ( 2, 6 ) Now in book it is written like set<neighbor> edges , How can it be a set ?? I need to store two int values , so how it can be set ?? Can't it be a Map ?? I am confused, can anyone help me ??

Thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Code : 


using namespace std;
static int index = 0;
class neighbor
{
    public:
            int dest ;
            int weight;
            neighbor( int d= 0, int w= 0)
            {
                dest = d ; weight = w;
            }

};
template<typename T>
class vertexInfo
{
    public:
            enum vertexColor { white , grey , black } ;
            typename  map< T, int>:: iterator vtxMapLoc;
            set<neighbor> edges;
             vertexInfo<T>(int index)
             {}
             vertexInfo<T>( typename  map<T, int> :: iterator& iter) : vtxMapLoc{*iter}
             {}

};
template <typename T>
class graph
{
    private:

            typename  map< T, int > :: iterator iter;
            map <T,int> vtxMap;
            vector<vertexInfo<T> > vInfo;
            int numVertices;
            int numedges;
            stack<int> availStack;
            int getvInfoIndex(graph<T>& , const T& v);
    public:
            void addEdge( graph<T>& , const T& , const T&, int );
            set<T> get_Neighbor( graph<T>& , const T& v) ;
            void show(graph<T>& );


};
int main()
{
    graph<char> g;
    char neighbor;
    g.addEdge(g,'A','B', 2);

    return 0;
}

template <typename T>
void graph<T> :: addEdge ( graph<T> & g, const T& v1 , const T& v2, int w)
{
    pair <map <char, int> :: iterator, bool> ret ;

     ret = g.vtxMap.insert(pair <char, int >( v1, index));

     if( ret.second)
     {
        index++;
        g.vInfo.push_back(index);
        (*g.vInfo[index].vtxMapLoc) = vtxMap[index]; // getting error 

      }

     ret = g.vtxMap.insert(pair <char, int >(v2 , index));

     if( ret.second)
     {
        index++;
        g.vInfo.push_back(index);
      }
Line 41: getvInfoIndex() doesn't need to take a graph<T> reference as a parameter. That's what this is for.

Lines 43-45: Same comment as above.

Rather than storing a map<T,int> and vector<vertexInfo<T>> in graph, why not store the data like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template <typenameT>
class vertexInfo<T> {
public:
    T data;
    set <neighbor<T> > edges;
    // vertextInfos compare on their data
    bool operator<(const vertextInfo<T> & right) const { return data < right.data}
    ...
};

template <typename T>
class graph {
private:
    set <vertextInfo<T> > nodes;
}

Topic archived. No new replies allowed.