c Language sparse matrix Question!

Asked 2 years ago, Updated 2 years ago, 62 views

How do you write a function that compares the subscripts (i,j) and (x,y) of the elements in two matrices and the order of the elements given?

int Compare(int i, int j, int x, int y) if((i,j) < (x,y)) return -1 else if ((i,j)>(x,y)) return 1 else return 0 I got a hint that I can solve it like this! I can't continue <

c sparse_matrix matrix

2022-09-22 19:57

1 Answers

int pos(int sparseMatrix[][2], int size, int, int, intc)
{
    int ret = 0;

    for(int i = 0; i < size; i++)
    {
        if (the row of the i-th element of the sparse matrix is less than r)
        {
            ret += 1;
        }
        else if (the row of the i-th element of the sparse matrix equals r)
        {
            if (the column of the i-th element of the sparse matrix is less than c)
            {
                ret += 1;
            }
        }
    }

    return ret;
}

변수 Introduction of variables

sparseMatrix[][2]: An array containing elements of a sparse matrix. (row, column) values.

ex) sparseMatrix[0][0] : row of first elements, sparseMatrix[0][1]: columns of first elements

size: Number of elements in the corresponding sparse matrix

r : row of elements you want to know their location

c : Heat of element you want to know location

ret : Location of the element

Use the function above to locate each element and then compare it.


2022-09-22 19:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.