Comma Operator with indexing 2D arrays

前端 未结 1 1730
一生所求
一生所求 2020-12-22 07:30

I have this algorithm that is pseudocode for the dijkstra algorithm for graph theory. The first thing that goes on is a basic for loop.

visitedSet[0] = true          


        
相关标签:
1条回答
  • 2020-12-22 08:11

    You have to review how to access elements of 2D array. Also, take look at what comma operator does. You have to use [] twice:

    adjacencyMatrix[0][i]
    

    The following:

    adjacencyMatrix[0, i]
    

    is equivalent to:

    adjacencyMatrix[i]
    

    Which will still leave you with 1D array. And, as the error message says:

       distanceArray[i] = adjacencyMatrix[i];
    // ^^^^^^^^^^^^^^^^   ^^^^^^^^^^^^^^^^^^
    //   unsigned int   array of unsigned ints
    

    You can not possibly expect this assignment to happen.

    0 讨论(0)
提交回复
热议问题