HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, a jagged array, also known as a ragged array or irregular array is an
array An array is a systematic arrangement of similar objects, usually in rows and columns. Things called an array include: {{TOC right Music * In twelve-tone and serial composition, the presentation of simultaneous twelve-tone sets such that the ...
of arrays of which the member arrays can be of different lengths, producing rows of jagged edges when visualized as output. In contrast, two-dimensional arrays are always rectangular so jagged arrays should not be confused with multidimensional arrays, but the former is often used to emulate the latter. Arrays of arrays in languages such as Java, PHP, Python (multidimensional lists), Ruby, C#.NET,
Visual Basic.NET Visual Basic (VB), originally called Visual Basic .NET (VB.NET), is a multi-paradigm, object-oriented programming language developed by Microsoft and implemented on .NET, Mono, and the .NET Framework. Microsoft launched VB.NET in 2002 as the ...
, Perl, JavaScript, Objective-C, Swift, and Atlas Autocode are implemented as
Iliffe vector In computer programming, an Iliffe vector, also known as a display, is a data structure used to implement multi-dimensional array data structure, arrays. Data structure An Iliffe vector for an ''n''-dimensional array (where ''n'' ≥ 2) ...
s.


Examples

In C# and
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
jagged arrays can be created with the following code: int[][] c; c = new int[2][]; // creates 2 rows c = new int // 5 columns for row 0 c = new int[3]; // create 3 columns for row 1 In C (programming language), C and C++, a jagged array can be created (on the stack) using the following code: int jagged_row0[] = ; int jagged_row1[] = ; int *jagged[] = ; In C/C++, jagged arrays can also be created (on the heap) with an array of pointers: int *jagged jagged = malloc(sizeof(int) * 10); jagged = malloc(sizeof(int) * 3); In
C++/CLI C++/CLI is a variant of the C++ programming language, modified for Common Language Infrastructure. It has been part of Visual Studio 2005 and later, and provides interoperability with other .NET languages such as C#. Microsoft created C++/CLI ...
, jagged array can be created with the code: using namespace System; int main() In Fortran, a jagged array can be created using derived types with allocatable component(s): type :: Jagged_type integer, allocatable :: row(:) end type Jagged_type type(Jagged_type) :: Jagged(3) Jagged(1)%row = Jagged(2)%row = ,2Jagged(3)%row = ,2,3 In Python, jagged arrays are not native but one can use
list comprehensions A list comprehension is a syntactic construct available in some programming languages for creating a list based on existing lists. It follows the form of the mathematical '' set-builder notation'' (''set comprehension'') as distinct from the use o ...
to create a multi-dimensional list which supports any dimensional matrix: multi_list_3d = [for i in range(3)">[.html" ;"title="[">[for i in range(3)for i in range(3)">html"_;"title="[">[<_a>for_i_in_range(3).html" ;"title="[.html" ;"title="[">[for i in range(3)">[.html" ;"title="[">[for i in range(3)for i in range(3)# Produces: [], [], [, ], [], [, ], [], [] multi_list_5d = [for i in range(5)] for i in range(5)] # Produces: [], [], [], [], [, ], [], [], [], [, ], [], [], [], [, ], [], [], [], [, ], [], [], [], []


See also

* Variable-length array *
Iliffe vector In computer programming, an Iliffe vector, also known as a display, is a data structure used to implement multi-dimensional array data structure, arrays. Data structure An Iliffe vector for an ''n''-dimensional array (where ''n'' ≥ 2) ...


References

{{reflist Arrays Articles with example Python (programming language) code