Data Structure _ fig _ calculate the nodes of an undirected graph

Source: Internet
Author: User

"Head. H"

# Include <iostream> using namespace STD; # define max_vex_num 20 class childnode // store another vertex of one vertex edge {public: childnode (); int child; childnode * Next;}; childnode: childnode () {Child = 0; next = NULL;} class vexnode // vertex information {public: vexnode (); char name; int visitsq; // access sequence int low; // low value childnode * firstchild;}; vexnode: vexnode () {visitsq = low = 0; firstchild = NULL ;} class vexbox // vertex set {public: vexbox (); int vexnum; vexnode vexbox [m Ax_vex_num] ;}; vexbox: vexbox () {vexnum = 0 ;}class artpoint // articulation point // close node class {public: void getartpoint (); // interface function PRIVATE: void getvexnode (); // obtain the vertex information void getedge (); // obtain the edge information void findarticul (); // retrieve the Customs node void dfsarticul (INT); // The depth first traversal graph vexbox V; int count ;}; void artpoint: getartpoint () // interface function {getvexnode (); // obtain the vertex information getedge (); // obtain the edge information findarticul (); // find the key node} void artpoint: getvexnode () // obtain the vertex information {cout <"Please input th E name of the vertex: "<Endl; char name; while (CIN> name) {v. vexbox [v. vexnum ++]. name = Name;} cin. clear ();} void artpoint: getedge () // obtain the edge information {cout <"Please input the two nodes which made a edge: "<Endl; int T [2]; childnode * P, * newnode; while (CIN> T [0]> T [1]) {for (INT I = 0; I <2; I ++) {newnode = new childnode; newnode-> child = T [1-I]; If (P = v. vexbox [T [I]. firstchild) = NULL) {v. vexbox [T [I]. firstchild = newnode ;} Else {While (p-> next! = NULL) {P = p-> next;} p-> next = newnode ;}} cin. clear ();} void artpoint: findarticul () // {COUNT = 1; // initialize the Count record access order v. vexbox [0]. visitsq = 1; dfsarticul (0); // access if (count <v. vexnum) // if the root of the Spanning Tree has two or more subtree {cout <v. vexbox [0]. name <Endl; // This node is output from the close node} For (INT I = 1; I <v. vexnum; I ++) // access the remaining unaccessed nodes {If (v. vexbox [I]. visitsq = 0) {dfsarticul (I) ;}} void artpoint: dfsarticul (INT N) // depth-first traversal graph {// the low value of the node is defined as min {access order of the current node, and the low value of the child node, Access sequence of the ancestor node} int min = v. vexbox [N]. visitsq = ++ count; // initialize minchildnode * P = v. vexbox [N]. firstchild; while (P! = NULL) // access all vertices that have edges connected to the vertex {If (v. vexbox [p-> child]. visitsq = 0) // access the child node {dfsarticul (p-> child); // The depth first traversal graph starting with this vertex if (v. vexbox [p-> child]. low <min) // if the child node's low value is Min = v. vexbox [p-> child]. low; // update the current node's low value if (v. vexbox [p-> child]. low> = v. vexbox [N]. visitsq) // if the child node's low value is greater than or equal to the access order of the current node // It indicates that the root node of the tree and other nodes in the subtree do not point to the current node's ancestor node cout <v. vexbox [N]. name <Endl; // This node is a closed node} else if (v. vexbox [p-> child]. visitsq <min) // access the ancestor node // update Minmin = V if necessary. vexbox [p-> child]. visitsq; P = p-> next;} // whilev. vexbox [N]. low = min; // use the minimum obtained min as the low value of the current node}

"Main. cpp"

 
# Include "head. H" int main () {artpoint P; p. getartpoint (); System ("pause ");}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.