C ++ implementation of the warshall Algorithm

Source: Internet
Author: User

Evaluate the closure of a linkAlgorithmThe time complexity is the fourth power of N. This algorithm is the third power of N, so warshall won the Tulin award.

# Include <iostream. h>
# Include <stdio. h>
# Include <stdlib. h>

Void main ()
{
Int n_dim = 0;
Cout <"input number of dimensions :";
Cin> n_dim;

Char ** array = new char * [n_dim]; // The following figure shows how to dynamically create an n_dim * n_dim array.
Char ch; // another article about Dynamic ArrayArticle

For (INT I = 0; I <n_dim; I ++)
{
Array [I] = new char [n_dim]; // This sentence is also
For (Int J = 0; j <n_dim; j ++)
{
Cin> CH;
Array [I] [J] = CH;
}
}

For (I = 0; I <n_dim; I ++)
For (Int J = 0; j <n_dim; j ++)
For (int K = 0; k <n_dim; k ++)
If (array [I] [J] = '1' & array [k] [I] = '1 ')
Array [k] [J] = '1 ';
Cout <"The trasitive closure of a relation R represented:" <Endl;
For (I = 0; I <n_dim; I ++)
{
For (Int J = 0; j <n_dim; j ++)
Cout <array [I] [J];
Cout <Endl;
}

}

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.