Skip to content

Some algo testing. Repo made for the sake of practicing data structure algorithms

Notifications You must be signed in to change notification settings

kateBea/Traverse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 

Repository files navigation

BFS and DFS test

Small program with C++ to test BFS and DFS traverse on graphs implemented as adjacency lists. There are still changes to be done.

Graph test

Important NOTE: The graph is assumed to be directed, i.e say we have a graph with 3 nodes {0, 1, 2}, insert edge (1,2) means we want to add an edge from vertex 1 to vertex 2 to the graph.

Example usage included in file main.cc:

    // create a new graph with 
    // nodes_count amount of vertices
    graph gph(nodes_count);

    std::cout << "graph size: " << gph.size() << '\n';
    std::cout << "graph degree: " << gph.grade() << '\n';

    std::cout << "\nAdding edges to the graph" << '\n';
    std::cout << "-------------------------------------------------------" << '\n';

    // add edges to the graph
    for (const auto& edg : edges)
        gph.add_edge(edg);

    if (gph.empty())    
        std::cout << "graph is empty" << '\n';
    else
        std::cout << "graph is not empty" << '\n';

    std::cout << "print the graph" << '\n';
    std::cout << gph << '\n';

    std::cout << "path followed with dfs" << '\n';
    dfs_path(gph);
    
    std::cout << '\n';

    std::cout << "path followed with bfs" << '\n';
    bfs_path(gph);

Click here for the graph example file used, and here its corresponding graphic representation.

Example building and execution on linux:

git clone repo
cd Traverse/src

mkdir build && cd build
cmake ..
cmake --build .

./traverse path_to_graph_file

Graph picture made with (can use to visualize graphs): Graph Editor

About

Some algo testing. Repo made for the sake of practicing data structure algorithms

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published