Graph Traversals in C++ and C#
Breadth First Search From WikiPedia : "Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key') and explores the neighbor nodes first, before moving to the next level neighbors" I have borrowed heavily the C++ code listing used at the 'Geeks for geeks' website and made a few modifications of my own, such as using smart pointers. I have also produced C# equivalents of the code. For reference the website is here: http://www.geeksforgeeks.org/breadth-first-traversal-for-a-graph/ Full C++/C# code listings: [tabs] [tab title="C++"] [code language="cpp"] #include <iostream> #include <list> #include <memory> class Graph { int _V; bool _directed; std::unique_ptr< std::list<int> > adj; public: Graph(int V, bool directed); ...