Jagged Array
Memory layout of a jagged array.

In computer science, a ragged array, also known as a jagged array, is an array of arrays of which the member arrays can be of different sizes and [1] producing rows of jagged edges when visualized as output. In contrast, two-dimensional arrays are always rectangular.[2]

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.

Examples

In C#, or Java[3] jagged arrays can be created with the following code:[4]

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:[5]

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: [6]

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)] # [[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]]


See also

References

  1. ^ Jesse Liberty; Brian MacDonald (18 November 2008). Learning C# 3.0. "O'Reilly Media, Inc.". pp. 210-. ISBN 978-0-596-55420-0. 
  2. ^ Don Box (2002). Essential .Net: The Common Language Runtime. Addison-Wesley Professional. p. 138. ISBN 978-0-201-73411-9. 
  3. ^ "Jagged Array in Java - GeeksforGeeks". GeeksforGeeks. 2016-02-03. Retrieved . 
  4. ^ Paul J. Deitel; Harvey M. Deitel (26 September 2008). C# 2008 for Programmers. Pearson Education. p. 40. ISBN 978-0-13-701188-9. 
  5. ^ "Jagged Arrays". FunctionX. Retrieved 2014. 
  6. ^ "Lists in Python Demystified". Alvin.io. Retrieved 2016. 



  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.

Jagged_array
 



 

Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.


Manage research, learning and skills at NCR Works. Create an account using LinkedIn to manage and organize your omni-channel knowledge. NCR Works is like a shopping cart for information -- helping you to save, discuss and share.


  Contact Us