Login
Order Now
Support
C++ Assignment Help on Display the Depth-First Search and Breadth-First Search

C++ Assignment Help on Display the Depth-First Search and Breadth-First Search

  • 31st Mar, 2022
  • 15:05 PM
#include "graph.hpp"

int main(){
    int s;
    cout << "Graph Traversals" << endl << endl;
    cout << "Enter starting city using number from 0 - 11: "; cin >> s;
    cout << "You entered city name: "<< vertices[s] << endl << endl;
    dfs_num.assign(num_vertices, 0);
    vi dfs_vertices;
    dfs(s, dfs_vertices);
    cout << "Starting at " << vertices[s] << ", " << dfs_vertices.size() << " cities are searched in this Depth-First Search order:\n";
    for(int vertex : dfs_vertices) cout << vertices[vertex] << ", ";
    cout << endl << endl;
    vi bfs_vertices;
    bfs(s, bfs_vertices);
    cout << "Starting at " << vertices[s] << ", " << bfs_vertices.size() << " cities are searched in this Breadth-First Search order:\n";
    for(int vertex : bfs_vertices) cout << vertices[vertex] << ", ";
    cout << endl << endl;
    char ch;
    while(1){
        cout << "Try another city (Y/N) "; cin >> ch;
        cout << endl;
        if(ch == 'N') break;
        cout << "Enter starting city using number from 0 - 11: "; cin >> s;
        cout << "You entered city name: "<< vertices[s] << endl << endl;
        dfs_num.assign(num_vertices, 0);
        dfs_vertices.clear();
        dfs(s, dfs_vertices);
        cout << "Starting at " << vertices[s] << ", " << dfs_vertices.size() << " cities are searched in this Depth-First Search order:\n";
        for(int vertex : dfs_vertices) cout << vertices[vertex] << ", ";
        cout << endl << endl;
        bfs_vertices.clear();
        bfs(s, bfs_vertices);
        cout << "Starting at " << vertices[s] << ", " << bfs_vertices.size() << " cities are searched in this Breadth-First Search order:\n";
        for(int vertex : bfs_vertices) cout << vertices[vertex] << ", ";
        cout << endl << endl;
    }
    
    return 0;
}

Share this post

assignment helpassignment helperassignment expertsassignment writing services