addIceCreamFlavorNode ( ' Strawberry ' ) graph. addIceCreamFlavorNode ( ' Chocolate Chip ' ) graph. Now that we have our three classes, we can add some data and test it out:Ĭonst graph = new Graph ( true ) graph. This will take in one argument, an IceCreamFlavorNode, and add it to the favoriteFlavors array.Ĭlass IceCreamFlavorNode favoriteFlavors: An array of IceCreamFlavorNodesĪdditionally, the PersonNode class will contain one method: addFlavor.The PersonNode constructor will contain two properties: The PersonNode class will take in one argument: a person’s name. It will be a directed graph, as people can like certain flavors, but flavors do not like people. We’re going to build a graph of people and ice cream flavors. There is no clear hierarchy of information in a graph. Note: The bi-directional arrows represent one edge, but for the sake of explicitness, I’ve drawn two arrows. The edge flows from one node to another.įor example, you might have a graph of people and movies where each person can have several favorite movies but movies do not have a favorite person.Īn undirected graph contains edges which flow bi-directionally, similar to a two-lane road with traffic going in both directions.įor example, you might have a graph of pets where each pet has an owner and each owner has a pet. A graph can be directed or undirected.Ī directed graph contains edges which function similar to a one-way street. Graphs are a data structure comprised of a collection of nodes with edges.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |