Questions tagged [jagged-arrays]

A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array of arrays." Use for questions about such arrays. If the array is multidimensional with all elements in each dimension being equal(eg: all rows have the same length), use [multidimensional-arrays] instead.

In computer science, a jagged array, also known as a ragged array, is an array of arrays of which the member arrays can be of different sizes, producing rows of jagged edges when visualized as output. In contrast, C-styled arrays are always rectangular; Arrays of arrays in languages such as Java, PHP, Python (multidimensional lists), Ruby, C#.Net, Visual Basic.NET, Perl, JavaScript, Objective-C, Swift, and Atlas Autocode are implemented as Iliffe vectors (come from here).

In C#, jagged arrays can be created with the following code:

int[][]c;
c=new int[2][]; // creates 2 rows
c[0]=new int[5]; // 5 columns for row 0
c[1]=new int[3]; // create 3 columns for row 1

In C++/CLI, jagged array can be created with the code:

using namespace System;
int main()
{
    array<array<double> ^> ^ Arrayname = gcnew array <array<double> ^> (4);// array contains 4 
    //elements
    return 0;
}

In Python, jagged arrays are not native but one can use list comprehensions to create a multi-dimensional list which supports any dimensional matrix:

 multi_list_3d = [[[] for i in range(3)] for i in range(3)] # [[[], [], []], [[], [], []], [[], [], []]]
 multi_list_5d = [[[] for i in range(5)] for i in range(5)] # [[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]]
582 questions
-3
votes
2 answers

C# How to: 2d array of jagged arrays?

I want to make a multidemesional array of jagged arrays. Is this possible? How? For Instance I see lokts of examples like the following: int[][,] jaggedArray4 = new int[3][,] I want to create the following: int[,,][] myFixedJagged = new…
Gullie667
  • 133
  • 11
-3
votes
1 answer

Trying to create a jagged array c++

int** DATA = new int*[10]; DATA[0] = new int[100]; //works DATA[1] = new int[100][5]; //dont work DATA[1][100] = 1; hello, i'm trying to create a jagged array, but need 5 columns. thanks
-3
votes
1 answer

C# How to create string type index in jagged array

I have php code as below $array[$x] = array(); $array[$x]["no"] = $no; $array[$x]["cid"] = $cid; $array[$x]["wait"] = $wait; $array[$x]["prio"] = $prio; $array[$x]["debug"] = $command[$i]; x++; Question: I want to have similar…
Aemz
  • 137
  • 1
  • 2
  • 9
-4
votes
3 answers

Get an array of string from a jagged array

I have a jagged array that contains other 1d string arrays: string[] first = {"one","two"}; string[] second = {"three","four"}; string[][] jagged = {first,second}; When I try to get the sub-arrays, they give a null value (I might be doing something…
KonaeAkira
  • 236
  • 1
  • 11
-4
votes
1 answer

Index of the first cell in jagged array in C#

What is the index of the first cell (the first left cell in first line and first row) in jagged array in C#? a[0][0]?? a[0][1]??
user3585203
  • 15
  • 1
  • 3
-4
votes
2 answers

How to pass a jagged array from one form to another form?

(New to C#) I am creating a jagged array form in C# as shown below, then pass it to form 2: // Answers jagged array that is declared in form 1 private Question[][] _answers; The following code is what I am using…
-5
votes
1 answer

How do you populate two Lists with one text file based on an attribute?

I have a text file with 40000 lines of data. The data is formatted as such: Anna,F,98273 Christopher,M,2736 Robert,M,827 Mary,F,7264 Anthony,M,8 ... I want to create two Lists based on a char value. The char indicates gender and I want to create a…
-5
votes
1 answer

C#: Why does an intermediate array need to be used for defining a jagged array?

I found a curious effect in some code I wrote that I don't understand. I found a workaround but I'd like to know why the original code doesn't work as expected. So populating a jagged array, I tried to define each cell individually. This resulted in…
Era
  • 171
  • 1
  • 5
  • 13
-6
votes
3 answers

How can I override next() for jagged array java?

I have a jagged array. How can I override next(), so I can get its elements step-by-step?
-6
votes
2 answers

Sum multidimensional array over dimensions

Suppose, that I have such jagged array (3 dimensions). int[][][] tab = new int[][][] { new int[][] { new int[] {1, 2, 3}, new int[] {4, 5, 6} }, new int[][] { new int[] {7, 8, 9}, new…
-6
votes
2 answers

Compare two byte arrays and find which one is bigger

I have a jagged byte array byte[][], I'm trying to get the max value of it's sub array items. I have created a method: private byte[] Max(byte[][] arrBytes) { var max = arrBytes[0]; foreach (var arr in arrBytes) { if (max != null…
SVI
  • 921
  • 4
  • 11
  • 23
-7
votes
1 answer

Array of arrays "newing" syntax is backwards?

In C#, when you "new" an array, it looks like this: int[] someArray = new int[5]; Which I read as: int-array someArray = new int-array-of-size-5 Today I casually tried to create an array of arrays like so: int[][] someArray = new int[][5]; To me,…
Clonkex
  • 3,373
  • 7
  • 38
  • 55
1 2 3
38
39