![]() Imagine an array as a group of people all in a row. You usually can only access list sequencially (begin at the first item and then go down the line) but manipulating them is easier because they aren't all stuck together in memory. ![]() Each item in the list points to the item after it (in the most basic implementation). An array is a collection of items where each item has an index, from 0 to (n-1), where n is the number of items in the array.Ī list is a linear sequence of items. It starts at memory address A and ends at memory address A+X. This makes it easy to add or remove items from the middle of the list, but difficult to access items (in order to get to item #4, you start from #0, from there to #1, to #2, etc.)Īn array is simply a block of data. ![]() The list can be a linked list - each item in the list holds a reference to the next item on the list (as in /u/EgNotaEkkiReddit's example). This for example is known as ArrayList in Java or List in C#. The actual data can be stored in an array, so it's easy to access any item in the middle of the list (you can ask for item #4 in the list for exapmle), but hard to add and remove items unless it's from the end of the list. Unlike an array, a list can have different implementations: ![]() You can add items to a list, remove items, sometimes even move items around. Usually fixed size (can't resize it without creating a new array and copying the items to it), with N elements stored sequentially in memory, numbered from 0 to N-1.Ī list is any sequential collection of items. As /u/EgNotaEkkiReddit wrote, an array is simply a block of data. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |