I'm trying to create a for loop or an alternative for a recursive backtracking problem. this is how i want the for loop to go through but i'm confused on how to implement it.
given an int[][] grid , row, and col
for(grid[row][col+1] then grid[row][col-1] then grid[row+1][col] then grid[row-1][col])
any tips would help a lot thanks!
6 1201
I'm trying to create a for loop or an alternative for a recursive backtracking problem. this is how i want the for loop to go through but i'm confused on how to implement it.
given an int[][] grid , row, and col
for(grid[row][col+1] then grid[row][col-1] then grid[row+1][col] then grid[row-1][col])
any tips would help a lot thanks!
I'm not quite sure I understand your question.
Do you mean, you want to go through all possible values for row and col and use those 4 values in every run? Or are you trying to write one for loop, which will go through exactly these 4 values and nothing else?
Greetings,
Nepomuk
I'm not quite sure I understand your question.
Do you mean, you want to go through all possible values for row and col and use those 4 values in every run? Or are you trying to write one for loop, which will go through exactly these 4 values and nothing else?
Greetings,
Nepomuk
exactly those 4 values, im writing a something similar to recursive backtracking maze algorithm where it goes north,west,east,south in a for loop.
You don't really need a for loop for that. Just put the statements into the code, if none of those four values ever change. Alternatively, if you feel you must use a loop, use - do { //code here } while(false);
A do loop is identical to a while loop except that it iterates the code once before checking the termination condition.
You don't really need a for loop for that. Just put the statements into the code, if none of those four values ever change. Alternatively, if you feel you must use a loop, use - do { //code here } while(false);
A do loop is identical to a while loop except that it iterates the code once before checking the termination condition.
the user inputs a 2d array so it will always be changing. i want it to run the for loop for the locations i specified up there
I'm trying to create a for loop or an alternative for a recursive backtracking problem. this is how i want the for loop to go through but i'm confused on how to implement it.
given an int[][] grid , row, and col
for(grid[row][col+1] then grid[row][col-1] then grid[row+1][col] then grid[row-1][col])
any tips would help a lot thanks!
Use auxiliary 'direction' arrays: -
int[] drow= { 0, 0, 1, -1 };
-
int[] dcol= { 1, -1, 0, 0 };
-
...
-
for (int i= 0; i < drow.length; i++)
-
// process grid[row+drow[i]][col+dcol[i]]
-
kind regards,
Jos
Use auxiliary 'direction' arrays: -
int[] drow= { 0, 0, 1, -1 };
-
int[] dcol= { 1, -1, 0, 0 };
-
...
-
for (int i= 0; i < drow.length; i++)
-
// process grid[row+drow[i]][col+dcol[i]]
-
kind regards,
Jos
thats what i was looking for, thanks a bunch!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: William Buchanan |
last post by:
Hi
I have the following stored proc in interbase (which might contain
errors - i'm doing it off the top of my head), which I would like to
convert into oracle. Can you help? What I want back is...
|
by: nightsaber |
last post by:
<script language="JavaScript">
<!-- hide me
var the_number = prompt("how many words (3-5 is good)?", "4");
var the_string = "";
var a_word;
for (loop = 0; loop < the_number; loop++)
{...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: al2004 |
last post by:
Write a program that reads information about youth soccer teams from a file, calculates the average score for
each team and prints the averages in a neatly formatted table along with the team name....
|
by: trunxnirvana007 |
last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
'UPGRADE_WARNING: Couldn't resolve...
|
by: TF |
last post by:
Hello all,
I made a ASP.NET 2.0 site that shows possible "recipes" for paint
colors stored in an access dbase. Basically, 1000 colors are stored
with specific RGB values in separate columns. A...
|
by: jenipriya |
last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors...
The table structures i hav
Employee (EmpID,...
|
by: shrik |
last post by:
I have following error :
Total giant files in replay configuration file are :
File name : /new_file/prob1.rec
Given file /new_file/prob1.rec is successfully verified.
Splitting for giant file...
|
by: c |
last post by:
Hi every one,
Me and my Cousin were talking about C and C#, I love C and he loves
C#..and were talking C is ...blah blah...C# is Blah Blah ...etc
and then we decided to write a program that...
|
by: mshroom12 |
last post by:
Hello to all. I am having difficulty trying to do this Java project using Eclipse. The following is what I have to do.
Election Day It's almost election day and the election officials need a...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |