using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;/// <summary>/// Summary description for Board/// </summary>public class Sudoku{private static Random rnd;const int colomns = 6;const int rows = 6;//encapsulationstatic int[,] Luach=new int[colomns,rows];//properties //constructorspublic Sudoku(){//// TODO: Add constructor logic here//}public static void InitGame(Label L) {int z=1;for (int r = 0; r < rows; r++) {for (int c = 0; c < colomns; c++) { Luach[r, c] = z; z++;if (z == 7) z = 1; L.Text += Luach[r, c].ToString() +" "; } z++; L.Text +="#"; } }public static void SwapRows() { }}Hello !
I'm completely novice and I was given a task at school:
I
I wrote the function InitGame in my class "Sudoku" and that function writes numbers ranging from 1 to 6 when the parameter is "z" and as you can see it goes from 1 to 7 and when it gets
to "7" and goes back to "1"
Now I have a 2 dimensional array called "Luach"
the paramet for rows is "r" and for colomns is "c".
Now the next thing I have to do (and here I face difficulty) is to swap the rows N times (Using the Random)
I print the numbers in onr row and # separates between each rows (I have a 2 dimensional array).
I should write the code for it in a separate function in the class called "SwapRows:
So please tell me what to write so that I can swap the rows N times.
Thanks !!!
// -- SwapRows ------------ // // Input: Two Dimensional array, which rows to swapprivate void SwapRows(int[,] AnArray,int RowA,int RowB) {// creat a temp rowint[] TempArray =new int[AnArray.GetLength(1)];// Store Row Afor (int Col = 0; Col < AnArray.GetLength(1); Col++) TempArray[Col] = AnArray[RowA, Col];// Copy Row B onto Row Afor (int Col = 0; Col < AnArray.GetLength(1); Col++) AnArray[RowA, Col] = AnArray[RowB, Col];// Copy the Temp row onto Row Bfor (int Col = 0; Col < AnArray.GetLength(1); Col++) AnArray[RowB, Col] = TempArray[Col]; }
0 comments:
Post a Comment