March 2019
Intermediate to advanced
336 pages
9h 9m
English
The main method creates a social graph by invoking the NewSocialGraph method. The links from 0 to 1, 0 to 2, 1 to 3, and 2 to 4 are added to the social graph. The links are printed using the printLinks method:
// main methodfunc main() { var socialGraph *SocialGraph socialGraph = NewSocialGraph(4) socialGraph.AddLink(0, 1, 1) socialGraph.AddLink(0, 2, 1) socialGraph.AddLink(1, 3, 1) socialGraph.AddLink(2, 4, 1) socialGraph.PrintLinks()}
Run the following command to execute the social_graph.go file:
go run social_graph.go
The output is as follows:

In the next section, we will take a look at the unit test for the social graph ...
Read now
Unlock full access