ok i have a 2d array and i want to trace through it.
The Array is
RDL
DLU
i have an entry point of Row1 Col1 which i think is letter R. On this array R means shift right L is shift left U shift up and D shift Down. I need to write i a function that will trace though the array and print the path and the ending point. Im not sure how to do this but this is what i have. I think it somewhat on the right track. The name of the array is Maze.

if(Maze[StartR][StartC]='U') 
{StartR=StartR+1;
 cout<<StartR<<StartC;}

else if(Maze[StartR][StartC]='D')
{StartR=StartR-1;
cout<<StartR<<StartC;}

else if(Maze[StartR][StartC]='L')
{StartC=StartC+1;
cout<<StartR<<StartC;}

else if(Maze[StartR][StartC]='R')
{StartC=StartC-1;
cout<<StartR<<StartC;}

Edited 6 Years Ago by Jeff_5_7: n/a

In C++, arrays start from index 0. In your case that would be row 0 column 0. Not sure what you mean by entry point. Do you want to start from row 1 column 1?

'=' is not a comparison operator. It is an assignment operator.

Edited 6 Years Ago by thomas_naveen: n/a

Arrays start from index 0. In your case that would be row 0 column 0. Not sure what you mean by entry point. Do you want to start from row 1 column 1?

'=' is not a comparison operator. It is an assignment operator.

yes start at Row 1 Col 1

Assumptions:

I am assuming that your problem statement refers to position.

Shift up means previous row and shift down means next row.

Shift left means go to the previous column and shift right means go to the next column.

In that case

0    1    2


0   R    D    L


1   D    L    U

For the above array, starting from 1, 1.

L means go to 1,0. (D)

D at (1,0) pushes the value to 2,0 which is out of bounds and the iteration should end there without accessing the 2,0 element.

If you have had the patience to read this far,

the above check can be done by putting the code in a loop, where you implement proper checks and read the array based on row and column values.

Exit:

Exit condition should be when the array goes out of bounds. (Take care not to read the out of bounds value by putting a check on your row and column counters.)

Have another exit condition which checks that after n proper traversals in the array the loop exits.

Edited 6 Years Ago by thomas_naveen: n/a

ok i have a 2d array and i want to trace through it.
The Array is
RDL
DLU
i have an entry point of Row1 Col1 which i think is letter R. On this array R means shift right L is shift left U shift up and D shift Down. I need to write i a function that will trace though the array and print the path and the ending point. Im not sure how to do this but this is what i have. I think it somewhat on the right track. The name of the array is Maze.

if(Maze[StartR][StartC]='U') 
{StartR=StartR+1;
 cout<<StartR<<StartC;}

else if(Maze[StartR][StartC]='D')
{StartR=StartR-1;
cout<<StartR<<StartC;}

else if(Maze[StartR][StartC]='L')
{StartC=StartC+1;
cout<<StartR<<StartC;}

else if(Maze[StartR][StartC]='R')
{StartC=StartC-1;
cout<<StartR<<StartC;}

All your directions are backwards. Down and Right are +1.

Other than that, you are on the right track.

As implied in the other posts,
1) What's the starting point? Are your columns 1,2,3 or 01,2?
2) What designates the ending point? How is it determined?
And to reiterate, be careful about falling off the edges of the maze.

All your directions are backwards. Down and Right are +1.

Other than that, you are on the right track.

As implied in the other posts,
1) What's the starting point? Are your columns 1,2,3 or 01,2?
2) What designates the ending point? How is it determined?
And to reiterate, be careful about falling off the edges of the maze.

Here is my data file
2 3RDLDLU 1 1 Where i build an array of 2 Rows and 3 columns
RDL
DLU Starting point of Row 1 Col 1. I am supposed to trace the path from that starting point until he path fall out side the array bounds. Im really no sure if it starts at 0 or 1. But lets say we start at Row1 Col1. We would go right to R1 C2 then go down to R2 C2 then left to R2 C1 where we would go down and exit the array bounds. I need to print the entry point being R1,C1 then the path which would be 1,1 1,2 2,2 2,1 then print the exit point R2 C1

This article has been dead for over six months. Start a new discussion instead.