Tagged Questions
0
votes
2answers
18 views
Multi-dimensional array in Mongoose schema
How can I define a multi-dimensional array in a Mongoose schema? I want to have a 2d array in my mongoose schema in order to locate a room in a hotel something like this.
var Room = new Schema({
...
1
vote
2answers
28 views
Filling in the main diagonals in a 2D array
I am trying to write a code that fills in the 2 main diagonals in an NxN matrix, for example:
if N=5 (which is entered through command line), we would have a 5x5 matrix filled with zeros and the ...
0
votes
2answers
23 views
Why does this code for shifting left in a 2D array not work and shifts left 2 instead?
This code is to shift a 2D array "arr" to the left completely once it runs through, but for some reason, the elements are shifting over by two.
public static void shiftLeft()
{
...
0
votes
4answers
40 views
Passing and returning 2d arrays in C++
So I am new to c++ and I have written this piece of c++ code.
#include <iostream>
using namespace std;
int** mat_mult(int mat1[2][2], int mat2[2][2]){
int mat3[2][2] = {{0,0},{0,0}};
...
-1
votes
1answer
39 views
2D Array in Java with number manipulation
My goal is to
Create a 5x5 array and fill it with random integers in the range of 1 to 25.
Print this original array
Process the array, counting the number of odds, evens, and summing all of the ...
0
votes
3answers
57 views
Calculate only the first dimension elements in a two dimension array?
I have a two dimension array that stores coordinates (xy) int arr[3][3]. How do I do calculations to only one of the dimensions in the array?
If I am interested in the average of the x coordinates I ...
0
votes
2answers
92 views
How to input multi-word string in C
I have this program. I want to input multi-word strings in a 2-D array. But instead of input whole string in first array of 2-D array this program inputs the first three words of my String in the ...
1
vote
1answer
151 views
Find all possible rectangles based on point in 2D Grid
I got the following map
local Map = {
[1] = {
[1] = 'Sand',
[2] = 'Sand',
[3] = 'Sand'
},
[2] = {
[1] = 'Sand',
[2] = 'Sand',
[3] = 'Grass'
...
1
vote
3answers
1k views
Dynamically allocated 2 dimensional array
I am trying to build two dimensional array by dynamically allocating. My question is that is it possible that its first dimension would take 100 values, then second dimension would take variable ...
0
votes
1answer
74 views
Trouble Resizing a 2D Array in C
I have a project where I create a 2D char array that stores words, with the option to add more words, and then resize the array when necessary. I'm getting a variety of errors as I try to play with it ...
0
votes
2answers
692 views
Java - Trouble creating a 2D array from a text file
I have a text file that is formatted as a square array. I am trying to convert this to a 2 dimensional array in Java. "st" is the text file described below.
This is my code:
public ...
0
votes
1answer
71 views
Parsing 2 dimension array without foreach or for using inbuilt array function [closed]
I have array in this format...
[User] => Array
(
[Oct 09] => Array
(
[10] => 1
[8] => 0
[9] => 0
...
1
vote
2answers
116 views
Printing Sepcific values on a Two Dimensional Array - Java
I have created a 2D Array as follows
String names [][] = new String [5][2];
for(int i=0; i<names.length;i++){
System.out.println(names[i][1]);
System.out.println(names[i][0]);
}
And the ...
0
votes
1answer
85 views
javascript 2D array iteration returning undefined function args
I am going through an exercise to recreate Conway's Game of Life and I have a basic strategy and I'm still very much in the "making it work" stage, so I know this looks pretty funny.
The problem I'm ...
1
vote
4answers
161 views
php - how to merge 2d array that have different no of element for each array
I have 2 set of 2d array and i want merge into 1 2d array. but the number of element in each array its not same and for the first 2 element is same and i don't want to duplicate it.
here its is.
...
1
vote
3answers
1k views
Best way to move around a 2d Array (Board Game)
I am curious about what would be the easiest way to move around a 2d array in Java? I created a 2d array for a game board and use that to keep track of the positions of game pieces. So if I have a ...
0
votes
1answer
81 views
How do I subset a 2-dimensional array in Javascript?
I have been looking around, and seen that it is possible to retrieve an element from a two dimensional array with something like myArray[x][y]. However what I am looking to do take everything but the ...
1
vote
3answers
92 views
2D Array and pointer to a pointer
Question from a past exam paper:
"Which of the following:
int a[4][4], (*b)[4], *c[4], **d;
Could you pass into a function expecting a pointer to a pointer to an int
ie
int funct(int **);
...
1
vote
2answers
106 views
2D arrays passed through functions in c
I'm having a problem with my program. I need my program to read from a text file, the first consists of the dimensions of the 2d array the rest is the contents of the array. I have coded the readWord ...
2
votes
3answers
155 views
how do I allocate one block of memory with new?
I have a two dimensional array that I've allocated dynamically using new.
The problem is I want to allocate the memory as one connected block instead of in separated pieces to increase processing ...
2
votes
1answer
50 views
For an X dimensional array where X is greater than 1,is only the first dimension optional,rest are mandatory?
I am trying to get my head around this but since I am new to C I just can't imagine how it will be at or beyond 3D arrays.I know we have to mention the size of static 1D arrays,but in 2D arrays,the ...
1
vote
1answer
287 views
How to handle an object array of Object Arrays
I have this code:
Object [] array=new Object array [5];
array[0]= new Object[3];
array[1]=new Object [10];
array[2]=new Object [7];
...
How can I access the 5th element of array[1].
If it was a 2D ...
-5
votes
3answers
673 views
Searching a 2d Array for a char (c++) [closed]
we have a 2d array, 10x10, with characters. In there is a certain character we need to find so we can print it out and each other character around it. EXAMPLE:
OOOOOOOOO
OOOOOOOOO
OOOOOOOOO
OOOOOOOOO
...
1
vote
3answers
178 views
Sorting 2D-array as a whole
I have a 2D array to sort as a whole using Java.
I have looked at the various links
How to sort a two-dimension ArrayList using comparators.
But it always sorts on a specific element. I want to ...
1
vote
2answers
642 views
2D Array neighboring algorithm
I have a 2D array like this:
0,1,0,0,1
1,0,1,0,1
0,1,1,0,1
0,1,0,1,1
1,1,0,0,1
If we extract the coordinates of all the 1's we get:
(height,width)
1,2
1,5
2,1
...
So now I want to find the ...
-1
votes
2answers
126 views
Reversi like game detect color diagonally (any help?) [closed]
I am recreating the classic Reversi game but I am having trouble on trying to correctly change colors diagonally. I have two for loops but they are not working correctly can anyone have a look at my ...
0
votes
1answer
257 views
Prind index of 2D Array using the click event
The code below display the index of each button when clicked the buttons are in an array but all this is done in form load. But I want to do the same thing in the click event and not in the form load ...
-3
votes
1answer
503 views
Convert Arraylist into a 2d Array?
I Basically wanted to take an input and store it into a 2D Array called mat with a 3x3 size
so i tried taking an input string, convert them into char and then sotring them in an array list and this ...
-2
votes
2answers
413 views
Return the index of the max number in a 2d array of ints in Ruby [closed]
I am trying to return the max value of an array of arrays in ruby
for 1d array this works
arr = [99, 3, 14, 11, 1, 12]
position = arr.each_index.max
how can I achieve the same thing for ...
-2
votes
2answers
1k views
Converting single dimensional array to 2D array in c#
I am having two 1D array. I want to convert these 2 arrays as single 2D array.
My code is:
public Static void Main()
{
int[] arrayRow;
int[] arrayCol;
for (int i = 0; i < row; i++)
{
for ...
1
vote
2answers
103 views
How can I make a variable size 2d array point to (and represent) the starting address of a 1d array in c?
I'm trying to do something as followed
float* A = fill_float(); //in other words A is full
float aIn2D[n/p][n] = &A; //the 2d array should be able to alter the 1d
I tried the above but wouldn't ...
0
votes
3answers
2k views
JavaScript Multi-Dimensional Array
I have a Student, who is in many courses, which have many Modules for each course.
So far, I have got:
var myStudent = new MySchool.Student("Bart", "Simpson", "0800 Reverse", "Some Street", ...
1
vote
1answer
266 views
Multi-dimensional array pascal syntac error
i did this and its working slightly better, now i get the error:
45 / 44 matric.pas
Fatal: Syntax error, ) expected but const char found
It is probable because i am using pascal graph.
program ...
-1
votes
3answers
900 views
2-dimensional array, IF condition checking
I've came across a problem when coding with C++ 2D array.
Just a little question, what does the code below mean?
...
if(array[x][y] >= 9){
...
}
...
Does that mean when the sum of x and y of ...
0
votes
2answers
220 views
2-D Array (row and column)
The program below (thanks to Sundial) computes the area of a rectangle
public class ComputeTheArea {
public static int areaOfTheRectangle (char[][] table, char ch) {
int[] first = new int[2];
...
-3
votes
6answers
353 views
2-Dimensional Array [closed]
We are given an assignment regarding 2-D array which states:
Please help me come up with an algorithm. I am new in Java and I'm having a hard time thinking of a pseudocode/code. All I know is
...
2
votes
6answers
473 views
Two-dimensional C array [closed]
I'm making a four in a row app, or, at least a class which calculates the best moves and stuff. The game board has a height of 6 and a width of 7. I'm not sure if I should name the instance variable ...
0
votes
2answers
6k views
Get the Rows and Columns from a 2D array matrix in Java
Suppose that I have a 2D array (matrix) in Java like this...
int[][] MyMat = {{0,1,2,3,4}, {9,8,7,6,5}};
If I want to extract the columns, I can do it easily like this...
int[] My0= MyMat[0]; ...
2
votes
5answers
3k views
How to check if two 2d arrays contain the same values java
I need to check if two 2d arrays ([5][5]) contain the same values.
Which means that I need the method to return true if the two arrays contain the same values even if that are arranged in a different ...
0
votes
1answer
666 views
filling 2dArrays with another 2DArray in Lua
is there a way to fill a 2d Array with another 2dArray in Lua? what im using right now is this
local T4 = {
{0, 0, 0, 0, 0},
{0, 0, 1, 0, 0},
{0, 1, 1, 1, 0},
{0, 0, 0, 0, 0},
{0, ...
0
votes
4answers
268 views
Writing attributes to an two dimensional array
This is my first time posting here, but I am in dire need of some Java expertise (or perhaps just another set of eyes).
I am writing an ArrayList of objects (Result) to a 2d array. I am trying to use ...
5
votes
3answers
200 views
Pass a 2-D array as an argument to function
If I dont know the size of both the dimensions of array and want to print a matrix using the following code
void printAnyMatrix(int (*A)[], int size_A, int size_B)
{
for (int ...
1
vote
2answers
269 views
How to project 2D array into new array in Ruby?
source_array = Array.new(5) { Array.new(10) }
source_array[3][4] = 0
source_array[2][5] = 1
source_array[4][2] = 0.5
Now, to create a new array destination_array of the same dimensions as ...
1
vote
1answer
499 views
Building a game via a 2D array - how to change color on part of the array?
I am still a beginner in java and I am attempting to create a game. I just created a 20 x 20 board that I added to a 2D array of squares. But, I am confused on some syntax....I still have a hard time ...
0
votes
2answers
293 views
Templated 2D Array Error
Dear Sir,
When I read an on-line book titled "Data Structures and Algorithms with Object-Oriented Design Patterns in C++", I cut and paste some code snippets from the section "Two-Dimensional Array ...
1
vote
2answers
353 views
Arithmetic operation so that 0, 1, & 2 return 0 | 3, 4, & 5 return 1, etc
I'm trying to take 9x9, 12x12, 15x15, etc. arrays and have the program interpret them as multiple 3x3 squares.
For example:
0 0 1 0 0 0 0 0 0
0 0 0 0 0 2 0 0 0
0 0 0 0 0 0 0 3 0
0 0 0 0 0 0 6 0 0
0 ...
1
vote
3answers
5k views
How to use a two-dimensional C array of Objective-C objects?
I have a two-dimensional C array of Objective-C objects. How do I access the members of those objects?
id array[5][5];
array[0][0] = [[Ball alloc] init];
The Ball class has two members:
int size;
...
249
votes
13answers
340k views
How can I create a two dimensional array in JavaScript?
I have been reading online and some places say it isn't possible, some say it is and then give an example and others refute the example, etc.
How do I declare a 2 dimensional array in JavaScript? ...