text cover

Data Abstraction and Problem Solving with C++

Walls and Mirrors

by Frank M. Carrano

Addison Wesley Logo

Graph.cpp

Go to the documentation of this file.
00001 
00019 #include "Graph.h"
00020 
00021 Graph::Graph(int n)
00022 {
00023    map<int, int> element;
00024    adjList.assign(n, element);
00025    numVertices = n;
00026    numEdges = 0;
00027 }  // end constructor
00028 
00029 int Graph::getNumVertices() const
00030 {
00031    return numVertices;
00032 }  // end getNumVertices
00033 
00034 int Graph::getNumEdges() const
00035 {
00036    return numEdges;
00037 }  // end getNumEdges
00038 
00039 int Graph::getWeight(Edge e) const
00040 {
00041    return e.weight;
00042 }  // end getWeight
00043 
00044 void Graph::add(Edge e)
00045 {
00046    int v = e.v,
00047        w = e.w,
00048        weight = e.weight;
00049 
00050    adjList[v].insert(make_pair(w, weight));
00051    adjList[w].insert(make_pair(v, weight));
00052    numEdges++;
00053 }  // end add
00054 
00055 void Graph::remove(Edge e)
00056 {
00057    int v = e.v,
00058        w = e.w,
00059        weight = e.weight;
00060 
00061    adjList[e.v].erase(w);
00062    adjList[e.w].erase(v);
00063    numEdges--;
00064 }  // end remove
00065 
00066 map<int, int>::iterator Graph::findEdge(int v, int w)
00067 {
00068    map<int, int> m = adjList[v];
00069    map<int, int>::iterator iter = m.find(w);
00070 
00071    return iter;
00072 }  // end findEdge

Generated on Sun Aug 27 22:27:07 2006 for AWLogo by  doxygen 1.4.6