int main(int argc, char *argv[])
{
     graph g;
    g = CreateGraph(9);
    g = AddEdgeDirected(g,1,2);
    g = AddEdgeDirected(g,1,4);
    g = AddEdgeDirected(g,1,3);
    //g = AddEdgeDirected(g,4,2);
    //g = AddEdgeDirected(g,3,4);
    g = AddEdgeDirected(g,3,5);
    g = AddEdgeDirected(g,4,6);
    g = AddEdgeDirected(g,5,9);
    g = AddEdgeDirected(g,5,8);
    g = AddEdgeDirected(g,9,7);
    //printf("%d ", Value(g[1].top->next));
    IsCyclicGraph(g);

}
Esempio n. 2
0
int main()
{
    Set<nodeT *> graph;
    Map<nodeT *> graphMap;
    
	InitGraphics();
	SetWindowTitle("Pathfinder");
    
    string backgroundFile;
    bool timeToQuit = false;
    
    
    cout << "This masterful piece of work is a graph extravaganza!" << endl;
    
    while (true) {
        
        cout << "Your options are:" << endl;
        cout << "(1) Choose a new graph data file" << endl;
        cout << "(2) Find shortest path using Dijkstra's algorithm" << endl;
        cout << "(3) Compute the minimal spanning tree using Kruskal's algorithm" << endl;
        cout << "(4) Determine if the graph has cycles" << endl;
        cout << "(5) Quit" << endl;
        cout << "Enter choice: ";
        
        int choice = GetInteger();
        string datafile;
        void UpdateDisplay();
        
        switch (choice) {
            case 1:
                cout << "Enter the name of the data file: ";
                datafile = GetLine();
                //datafile = "Small.txt";
                //datafile = "USA.txt";
                //datafile = "Stanford.txt";
                graph.clear();
                graphMap.clear();
                backgroundFile = ReadGraph(graph, graphMap, datafile);
                break;
            case 2:
                if (backgroundFile == "") {
                    cout << "No file is specified" << endl;
                }
                else {
                    UpdateDisplay();
                    MovePen(0,0);
                    DrawNamedPicture(backgroundFile);
                    DrawNodesAndArcs(graph);
                    cout << "(2) Finding shortest path using Dijkstra's algorithm" << endl;
                    HandleShortestPath(graph);
                }
                break;
            case 3:
                if (backgroundFile == "") {
                    cout << "No file is specified" << endl;
                }
                else {
                    cout << "(3) Computing the minimal spanning tree using Kruskal's algorithm" << endl;
                    UpdateDisplay();
                    MovePen(0,0);
                    DrawNamedPicture(backgroundFile);
                    //DrawNodesAndArcs(graph);
                    minimumSpanningTree(graph, graphMap);
                }
                break;
            case 4:
                if (backgroundFile == "") {
                    cout << "No file is specified" << endl;
                }
                else {
                    graphT graph2;
                    graph2.allNodes = graph;
                    
                    cout << "(4) Determining if the graph has cycles" << endl;
                    if (IsCyclicGraph(graph2))
                        cout << "Yes, it is cyclic" << endl;
                    else
                        cout << "No, it is not cyclic" << endl;
                }
                break;
            case 5:
                cout << "Thanks for using Pathfinder. Bye!" << endl;
                timeToQuit = true;
                break;
                
            default:
                cout << "Invalid choice" << endl;
                break;
        }
        
        if (timeToQuit) break;
        
    }
    return (0);
}