Using graphs to store data
In this recipe, we will see how easy it is to store data using the graph data structure. The graph data structure is extremely useful if we have to create a system like Facebook to sell and share our game with friends, and friends of friends. A graph can be implemented in a few ways. The most commonly used method is by using edges and nodes.
Getting ready
To work through this recipe, you will need a machine running Windows. You also need to have a working copy of Visual Studio installed on your Windows machine. No other prerequisites are required.
How to do it…
In this recipe, we will see how we can implement graphs. Graphs are a very good data structure for interconnecting various states and data together with edge conditions. Any social networking algorithm uses the graph data structure in one way or another:
Open Visual Studio.
Create a new C++ project.
Select Win32 Console Application.
Add the
CGraph.h
/CGraph.cpp
files.Add the following lines of code to
CGraph.h
:#include...