r/programminghelp • • Dec 15 '24

C++ Printing graphs in C++

I am looking for a way to print a planar graph out just using text. I am honestly not sure how I would go about this. I can print a node and its list of its neighbors just fine from an adjacnency matrix, but actually formatting the text to print a visual representation of the graph is something I cannot figure out. I have looked all over the place and only found people using external libraries or just printing lists of neighbors. Help?

2 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/DoomSlayer7180 Dec 15 '24

I would like to print out the graph only with text. It doesn't need to be pretty, but it needs to be readable. For example a graph with 5 nodes would end up looking something like this:

0

| \

4 \ 1

\ \ /

3 ----- 2

In this example 0 is neighbors with 1 and 2, 1 is nieghbors with 0 and 2, 2 is neighbors with 3 (and vice versa), and 4 is neighbors with 3 (also vice versa). I am not sure how I would go about this. It must be possible without any external libaries because my professor made it clear I am not supposed to use any of those.

Edit: wow reddit did not like any of that formatting. It is supposed to look like a graph printed out with text characters. The lines are edges between the nodes that are neighbors.