Graph method: Looking for the Java version __stl/algorithm of the non-graph Unicom subset

Source: Internet
Author: User

In the image processing, the dense method is used, that is, the image is processed by the pixel collection. In the image topology aspect, the graph computation method is applied more.

To find a Java version of the non-graph Unicom subset, code:

	Finds all connected subsets of undirected graphs//wishchin ... public static arraylist<set<integer>> findallcons (Boolean adjm[][]) {arraylist<set<integer>

		> consets = new arraylist<set<integer>> ();
		stack<integer> tree = new stack<integer> ();
		boolean[] IsTra = new Boolean[adjm.length];
		for (int i = 0; i < adjm.length ++i) {Istra[i] = (false); //Traverse each line for (int i = 0; i < adjm.length;)
				{if (istra[i] = = true) {++i;
			Continue
			} tree.push (i);
			set<integer> sub = new hashset<integer> ();
			Sub.add (i);
			Int J = Tree.peek ();

				while (!tree.isempty () && istra[j] = = False) {j = Tree.pop ();//Remove stack top I istra[j] = true; Traverse each column for (int k = 0; k < adjm[j].length ++k) {if (false = Istra[k]) {if (adjm[j][k] = = True &am
						p;& Istra[k] = = False) {Tree.push (k);//If K has not been traversed, then press into Stack Sub.add (k);
			}} j = Tree.peek ();
			} ++i;
		Consets.add (sub); }
		return consets; }

Precautions:

In Java, the set class is an abstract class that cannot be instantiated directly, and a subclass of set must be instantiated, such as HashSet.


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.