Search-deep Priority Search

Source: Internet
Author: User

 

Package search; import static Java. lang. system. out; public class deepfirstsearch {public static void main (string ARGs []) {// graph initialization int G [] [] = new int [9] [9]; // G [0] [1] = 1; G [1] [2] = 1; G [2] [3] = 1; G [1] [4] = 1; G [0] [5] = 1; G [5] [6] = 1; G [5] [7] = 1; int visited [] = new int [G. length]; for (INT I = 0; I <G. length; I ++) for (Int J = 0; j <G. length; j ++) if (G [I] [J] = 1) g [J] [I] = 1; go (G, visited );} /** this method is the execution of the depth-first search, which only searches for the current K-point All connected nodes **/public static void DFS (INT [] [] A, int visited [], int K) // start from start to find {visited [k] = 1; // access K node out. println (k); // access all nodes connected to K below for (INT I = 0; I <. length; I ++) {// if this node is connected to K and has not been accessed, then access this node if (a [k] [I] = 1 & visited [I]! = 1) DFS (A, visited, I) ;}/ ** this is an in-depth Priority Search for the entire image, this ensures that all nodes are searched again **/public static void go (INT [] [] A, int visited []) {// locate the point connected to K and find an access request to access a for (INT I = 0; I <. length; I ++) if (visited [I]! = 1) DFS (A, visited, I );}}

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.