Sample Program Using a Graph

//  main program to create a sample graph, print it and dfs it

#include <iostream.h>
#include <string>
#include "Graph.h"

int main()
{
  Graph g;
  string name;
  string from,to;

  cout << "Enter node names (enter q when finished):\n";
  cin >> name;
  while (name != "q")
    {
      g.addNode(name);
      cin >> name;
    }

  cout << "Enter edges (enter q when finished):\n";
  cin >> from;
  while (from != "q")
    {
      cin >> to;
      g.addEdge(from,to);
      cin >> from;
    }

  g.print();
  g.dfs();
}


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2001