Recusive shortest path findin in C

I wanna make a program that finds the shortest path from 0x0 to mxn point recursivly and change the values of the path to '-', one values in the matrix means path and zero means wall, and I can go in all directions.

I'm very frish, so please try to explain the details as much you can.

int startRow = 0, startColumn = 0;
char fun(char arr[][3]);

int main()
{   
   
    char matrix[3][3] = { {1,0,1},{1,1,0},{0,1,1} };
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            printf("%d\t", matrix[i][j]);
        }
        printf("\n");
    }

    fun(matrix);

    
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            printf("%d\t", matrix[i][j]);
        }
        printf("\n");
    }


    return 0;
}

char fun(char arr[][3])
{
    if (arr[startColumn][startRow+1] != 0)
    {
        arr[startColumn][startRow + 1] = '-';
        return fun(arr[startColumn][startRow + 1]);
    }

    else
    {   
        startRow = 0;
        return fun(arr[startColumn + 1][startRow]);

    }
}

the output shold be like this: the output shold be like this:



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation