// file: DenseGraph.h
// pg. 26, Algorithms in C++, Part 5, Robert Sedgewick
// An implemenation of the Graph using an Adjacency Matrix

#include <vector>
#include "Graph.h"

using namespace std;

#ifndef DENSE_GRAPH_H
#define DENSE_GRAPH_H

class DenseGraph
{
private:
  int vCount, eCount;
  bool digraph;
  vector< vector<bool> > adj;

public:
  DenseGraph(int v, bool di = false) :
    adj(v), vCount(v), eCount(0), digraph(di) {
    
    for (int i = 0; i < v; i++)
      adj[i].assign(v, false);
  }

  int V() const { return vCount;}
  int E() const { return eCount;}
  bool directed() const { return digraph;}
  void insert(Edge e) {
    int v = e.v;
    int w = e.w;
    if (adj[v][w] == false)
      eCount++;
    adj[v][w] = true;
    if (!digraph)
      adj[w][v] = true;
  }

  void remove(Edge e) {
    int v = e.v;
    int w = e.w;
    if (adj[v][w] == true)
      eCount--;
    adj[v][w] = false;
    if (!digraph)
      adj[w][v] = false;
  }

  bool edge(int v, int w) const {return adj[v][w];}

  class AdjIterator;
  friend class AdjIterator;
};

#endif
