0

I have to develop a program which checks if some undirected graph is bipartite in C++ as a project exam. I have created all necessary functions but I faced issue I do not clearly understand.

I have some custom struct:

struct slistEl
{
    slistEl* next;
    int v;
};

Then I have all logic which checks if the graph previously taken from the .txt file is bipartite:

bool isBipartite(int n, slistEl** A)
{
    queue Q;
    int* C;
    int v, u, i;
    slistEl* p;

    C = new int[n];      
    for (i = 0; i < n; i++) C[i] = 0;

    for (i = 0; i < n; i++)  
        if (!C[i])        
        {
            C[i] = 1;        
            Q.push(i);      

            while (!Q.empty()) 
            {
                v = Q.front();   
                Q.pop();         
                for (p = A[v]; p; p = p->next)
                {
                    u = p->v; 
                    if (C[u] == C[v])
                    {
                        delete[] C;
                        return false;
                    }

                    if (!C[u])
                    {
                        C[u] = -C[v];
                        Q.push(u);
                    }
                }
            }
        }

    delete[] C;

    return true;
}

void continueWork(vector<int[2]> verticles) {
    slistEl* p, * r, ** A;

    A = new slistEl * [getVerticlesCount(verticles)];


    for (int i = 0; i < getVerticlesCount(verticles); i++) A[i] = NULL;


    for (int i = 0; i < verticles.size(); i++)
    {
        slistEl v1;
        v1.v = verticles[i][0];
        slistEl v2;
        v2.v = verticles[i][1];

        p = new slistEl;   
        p->v = v2.v;         
        p->next = A[v1.v]; 
        A[v1.v] = p;
        p = new slistEl;
        p->v = v1.v;
        p->next = A[v2.v];
        A[v2.v] = p;
    }
}

Function getVerticalCounts has no impact for this issue- it counts verticals from the input file.

Then, I receive following issue which I tried to resolve like here in this issue but It did not help me in any way: Error in converting argument from 'const_Ty' to const custom struct

Errors I receive: '==': no conversion from 'const _Ty' to 'int [2]' an array cannot be initialized with a parenthesized initializer

Could someone explain to me specifically what this problem is and potentially how to fix it? I would be so grateful.

toledo1366
  • 29
  • 5
  • Please show the full compiler output, a [mre] would be helpful too. I don't think the error you've posted is even coming from this code. You might find that replacing `int[2]` with `std::array` helps – Alan Birtles Feb 18 '22 at 08:31
  • I recommend you to read this [issue](https://stackoverflow.com/questions/13651740/c-with-vectorint2-can-i-push-backsomenum1-somenum2). – Yujian Yao - MSFT Feb 18 '22 at 09:22
  • `vector` isn't going to work, because plain C-style arrays are not copyable, whereas `std::vector` requires its elements to be copyable or at least movable. Consider `std::vector>` or `std::vector>` – Igor Tandetnik Feb 19 '22 at 01:47

0 Answers0