In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-10-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the undirected graph of C++". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Undirected graph
If you draw casually on paper, or just give an exemplary description of the graph, most people will choose undirected graph. However, in the computer, the undirected graph is stored according to the method of directed graph-two directed edges. In fact, when we talk about non-directionality, we just ignore the direction-draw a line on the paper, is it possible that the line "whoosh" appears, not from one end to the other? Undirected graph has several unique concepts, such as connected components, link nodes, and minimum spanning tree. Before that, the basic operation of the undirected graph class is completed.
Undirected graph class
Template class Graph: public Network {public: Graph () {} Graph (dist maxdist): Network (maxdist) {} bool insertE (name v1, name v2, dist cost) {if (Network::insertE (v1, v2, cost)) return Network::insertE (v2, v1, cost); return false;}}
Just add an edge, and then add a reverse edge, it is very simple.
Connected component
This is unique to the undirected graph, and the directed graph is much more complex (strong, simple, and weakly connected). The reason is that the edge of the undirected graph can go any way, and the edge of the digraph seems to fall into the bottomless abyss and never climb up again. With DFS, the algorithm for finding connected components becomes very simple-just call DFS for each vertex that is not accessed.
Void components () {visited = new bool [vNum ()]; int I, j = 0; for (I = 0; I < vNum (); visited +) visited [I] = false; cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.