Home>

How to remove the matrix? I have such a mistake

#include <
iostream >
#Include <
Algorithm >
#Include <
Windows.h >
#Include <
Omp.h >
Using Namespace STD;
Class Graph {
Private:
    BOOL ** ADJMATRIX;
    BOOL ** PMATRIX;
    int numvertices;
    int * p; //Perestanovka
Public:
    Graph (int numvertices) {
        This->
numvertices= numvertices;
        adjmatrix= new bool * [numvertices];
        Pmatrix= new bool * [numvertices];
        for (int i= 0; i <
 Numvertices; I ++) {
            adjmatrix [i]= New Bool [Numvertices];
            PMATRIX [i]= new bool [numvertices];
            for (int j= 0; j <
 Numvertices; j ++) {
                adjmatrix [i] [j]= false;
                PMATRIX [i] [j]= false;
            }
        }
        p= new int [numvertices];
        for (int i= 0; i <
 Numvertices; I ++)
            p [i]= i;
    }
    int getnumvertices () {
        RETURN NUMVERTICES;
    }
    Void Addedge (int i, int j) {
        adjmatrix [i] [j]= True;
        adjmatrix [j] [i]= True;
    }
    int * getp () {
        Return P;
    }
    bool ** getadjmatrix () {
        RETURN ADJMATRIX;
    }
    INT * RETPER () {
        NEXT_PERMUTIATION (P + Numvertices);
        COUT <
≪
 "Remosting" <
≪
 Endl;
        for (int i= 0; i <
 Numvertices; I ++)
            COUT <
≪
 P [i] <
≪
 "";
        COUT <
≪
 Endl;
        Return P;
    }
    BOOL ** RETPMATRIX (INT * P) {
        for (int i= 0; i <
 Numvertices; I ++)
            for (int j= 0; j <
 Numvertices; j ++)
                PMATRIX [i] [j]= false;
        for (int i= 0; i <
 Numvertices; I ++)
            PMATRIX [p [i]] [i]= True;
        Return Pmatrix;
    }
    BOOL ** TRASPPMATRIX (BOOL ** PMATRIX) {
        BOOL ** TPMATRIX= NEW BOOL * [NUMVERTICES];
        for (int i= 0; i <
 Numvertices; I ++) {
            TPMATRIX [i]= new bool [numvertices];
            for (int j= 0; j <
 Numvertices; j ++)
                Tpmatrix [i] [j]= pmatrix [j] [i];
        }
        Return TPMATRIX;
    }
    BOOL ** MULMATRIX (BOOL ** A, BOOL ** B) {
        bool ** c= new bool * [numvertices];
        int i, j, k;
        for (i= 0; i <
 Numvertices; I ++) {
            C [i]= New Bool [Numvertices];
            for (j= 0; j <
 Numvertices; j ++)
                C [i] [j]= false;
        }
        for (i= 0; i <
 Numvertices; I ++) {
            for (j= 0; j <
 Numvertices; j ++)
                for (k= 0; k <
 Numvertices; k ++)
                    C [i] [j]= C [i] [j] || (A [I] [k] &
&
 B [k] [j]);
        }
        Return C;
    }
    Void PrintMatrix (Bool ** Matrix) {
        for (int i= 0; i <
 Numvertices; I ++) {
            COUT <
≪
 I <
≪
 ":";
            for (int j= 0; j <
 Numvertices; j ++)
                COUT <
≪
 Matrix [i] [j] <
≪
 "";
            COUT <
≪
 Endl;
        }
        COUT <
≪
 Endl;
    }
    Graph (Const Graph &
Graph): adjmatrix (graph.adjmatrix), PMATRIX (graph.pmatrix),
        Numvertices (Graph.Numvertices), P (Graph.p) {}
    ~ Graph () {
        for (int i= 0; i <
 Numvertices; ++ I) {
            delete [] adjmatrix [i];
            DELETE [] PMATRIX [i];
        }
        delete [] adjmatrix;
        delete [] pmatrix;
        Delete P;
    }
};
BOOL ISISOMORPH (Graph G1, Graph G2) {
    int * per= g1.getp ();
    bool ** iso= g1.mulmatrix (g1.mulmatrix (g1.retpmatrix (per), g1.getadjmatrix ()), g1.trasppmatrix (g1.retpmatrix (per)));
    if (g2.getadjmatrix ()== ISO)
        Return 1;
    ELSE.
        Return 0;
}
INT MAIN () {
    SetConsoleCP (1251);
    SetConsoleoutPutcp (1251);
    Double Start_Time, End_Time;
    Graph G1 (4), G2 (4);
    //Graph1 ////////
    g1.addedge (0, 1);
    g1.addedge (0, 2);
    g1.addedge (1, 2);
    g1.addedge (2, 3);
    //Graph2 /////////
    g2.addedge (0, 1);
    g2.addedge (0, 2);
    g2.addedge (1, 2);
    g2.addedge (2, 3);
    if (g1.getnumvertices ()== g2.getnumvertices ()) {If (g1.getadjmatrix ()!= g2.getadjmatrix ()) {cout <
≪
 "Count A" Count A &LT matrix;
≪
 Endl;
            g1.printMatrix (G1.Getadjmatrix ());
            COUT <
≪
 "Suitability of the Count B" <
≪
 Endl;
            g2.printmatrix (g2.getadjmatrix ());
            COUT <
≪
 "Initial rearrangement= [0, 1, 2, 3]" <
≪
 Endl; //it is not visible
            Start_Time= OMP_GET_WTIME ();
            if (isisomorph (g1, g2))
                COUT <
≪
 "Graphs are isomorphic" <
≪
 Endl;
            ELSE.
                COUT <
≪
 "Graphs are not isomorphic" <
≪
 Endl;
            END_TIME= OMP_GET_WTIME ();
            PrintF ("time at a measure of time% LF \ N", end_time -start_time);
        }
        ELSE.
            COUT <
≪
 "You have introduced identical graphs with the same matrices by adjacent, checking on isomorphism is not required" <
≪
 Endl;
    }
    ELSE.
        COUT <
≪
 "Error: The number of vertices does not coincide, the test on isomorphism deviates" <
≪
 Endl;
}

Do you have a copy designer?

KoVadim2021-06-09 11:43:23

@Kovadim no, and you need?

Stark2021-06-09 12:02:19

Of course you need. As soon as you try to pass on the value (and this will happen sooner or later), then everything will have a hanging pointers. The rule of three /five no one has canceled.

KoVadim2021-06-09 12:08:45

Show the use ... or copying, or assignment -that's the result: double deletion.

Harry2021-06-09 12:13:25

@Harry added all the code, and the copy constructor through the initialization lists, I do not know correctly or not

Stark2021-06-09 12:18:09
c++