Homework/HW10/graph.cc
void Graph::print()
{
    int i;
    if (directed)
        cout << "The graph is directed" << endl;
    else
        cout << "The graph is undirected" << endl;
    cout << "The graph contains " << numVertices
         << " vertices and " << numEdges << " edges" << endl;

    if (numVertices)
    {
        // print all the names
        cout << "The vertex names are: ";
        for (i = 0; i < numVertices; i++)
            cout << vertices[i].name << ' ';

        // print all the adjacency lists
        cout << endl
             << "The adjacency list for each vertex is:" << endl;
        for (i = 0; i < numVertices; i++)
        {
            cout << "vertex " << i << ": ";
            ListIntIter iter;
            iter = vertices[i].edgeList.begin();
            while (iter != vertices[i].edgeList.end())
            {
                // here we have an edge from i to *iter.
                cout << *iter << ' '; // output the content of the node
                iter++;               // move to the next node
            }
            cout << endl;
        }
    }
}
// Simple print of the graph.
Simple print of the graph.
Simple print of the graph .
void Graph::print()
{
    int i;
    if (directed)
        cout << "The graph is directed" << endl;
    else
        cout << "The graph is undirected" << endl;
    cout << "The graph contains " << numVertices
         << " vertices and " << numEdges << " edges" << endl;
    if (numVertices)
    {
        cout << "The vertex names are: ";
        for (i = 0; i < numVertices; i++)
            cout << vertices[i].name << ' ';
        cout << endl
             << "The adjacency list for each vertex is:" << endl;
        for (i = 0; i < numVertices; i++)
        {
            cout << "vertex " << i << ": ";
            ListIntIter iter;
            iter = vertices[i].edgeList.begin();
            while (iter != vertices[i].edgeList.end())
            {
                cout << *iter << ' '; 
                iter++;               
            }
            cout << endl;
        }
    }
}
void Graph :: print ( ) { int i ; if ( directed ) cout << " " << endl ; else cout << " " << endl ; cout << " " << numVertices << " " << numEdges << " " << endl ; if ( numVertices ) { cout << " " ; for ( i = 0 ; i < numVertices ; i ++ ) cout << vertices [ i ] . name << ' ' ; cout << endl << " " << endl ; for ( i = 0 ; i < numVertices ; i ++ ) { cout << " " << i << " " ; ListIntIter iter ; iter = vertices [ i ] . edgeList . begin ( ) ; while ( iter != vertices [ i ] . edgeList . end ( ) ) { cout << * iter << ' ' ; iter ++ ; } cout << endl ; } } }
Simple print of the graph.
Simple print of the graph .
// print all the names // print all the adjacency lists // here we have an edge from i to *iter. // output the content of the node // move to the next node