user1896464
user1896464

Reputation: 345

Unhandled exception Error in C++ Recursion

so i have this function which use recursion to find the longest sequence of numbers. but every time i run it, i get this error message:

Unhandled exception at 0x002871D9 in increasingSeq.exe: 0xC0000005: Access violation writing location 0x01060EC0.

int seqeter(int grid, int startPos,  int seq)
{
    Sequence maxseq;
    maxseq.size = 0;
    for (int rows=0;rows<MAXROWS;rows++)
    {
        for(int cols=0;cols<MAXCOLS;cols++)
        {

            if (grid[startPos.x][startPos.y] < grid[startPos.x+rows][startPos.y+cols])

            {
                return seq;
            }

            else 
            {
                maxseq.list[maxseq.size] = grid[startPos.x][startPos.y];
                maxseq.size ++;
             return generateSeq(grid, startPos, seq);
            }

        }
    }

    return maxseq;
}

Upvotes: 0

Views: 528

Answers (1)

SomeWittyUsername
SomeWittyUsername

Reputation: 18368

You're not advancing from your startPos - the recursion never stops and you quickly crash the stack.

Upvotes: 4

Related Questions