5 #ifndef DSALGLIB_GRAPH_H 6 #define DSALGLIB_GRAPH_H 27 arc(
long long int gvertex,
long long int weight)
37 bool operator==(arc temp)
39 if(end==temp.end&&cost==temp.cost)
52 gnode(type param,
long long int tindex)
65 long long int _getindex(type param)
67 long long int i,size=nodes.
size();
70 if(nodes[i].data==param)
return i;
75 long long int _getby_vindex(
long long int tvindex)
78 for(i=0;i<=tvindex;i++)
79 {
if(nodes[i].index==tvindex)
95 if(_getindex(param)>-1)
98 gnode vertex(param,vindex);
105 bool add_arc(type from,type to,
long long int weight=0)
107 long long int findex=-1,tindex=-1;
109 findex=_getindex(from);
110 tindex=_getindex(to);
112 if(findex<0||tindex<0)
return false;
113 arc edge(nodes[tindex].index,weight);
115 if(nodes[findex].outadj.
search(edge)>=0)
118 nodes[findex].outadj.
add_back(edge);
120 edge.end = nodes[findex].index;
130 long long int sindex = _getindex(param),temp,i,atemp;
135 visited[sindex]=
true;
139 fun(nodes[temp].data);
140 for(i=0;i<nodes[temp].outadj.
size();i++)
142 atemp = _getby_vindex(nodes[temp].outadj[i].end);
159 long long int sindex = _getindex(param),temp,i,atemp;
168 fun(nodes[temp].data);
169 for(i=0;i<nodes[temp].outadj.
size();i++)
171 atemp = _getby_vindex(nodes[temp].outadj[i].end);
187 long long int tindex = _getindex(param),i,size,tvindex;
188 if(tindex<0)
return false;
192 size = nodes[tindex].outadj.
size();
195 temparc = nodes[tindex].outadj[i];
196 tvindex = _getby_vindex(temparc.end);
197 nodes[tvindex].inadj.
remove(temparc);
200 size = nodes[tindex].inadj.
size();
203 temparc = nodes[tindex].inadj[i];
204 tvindex = _getby_vindex(temparc.end);
205 nodes[tvindex].outadj.
remove(temparc);
214 #endif //DSALGLIB_GRAPH_H bool add_vertex(type param)
bool dfstraverse(type param, void(fun)(type obj))
bool bfstraverse(type param, void(fun)(type obj))
void add_back(type param)
bool add_arc(type from, type to, long long int weight=0)
void remove_at(long long int index)
bool remove_vertex(type param)
long long int search(type svalue)