Please enable JavaScript.
Coggle requires JavaScript to display documents.
Arrays/LIsts (One dimensional arrays (An alternative to storing all data…
Arrays/LIsts
One dimensional arrays
An alternative to storing all data as separate variables is to use an array. The array is given a single name and is associated with each of the entries in it. For example:
football_team = ("John Smith", "Harry Potter", "Jimmy Carr", ... )
An array is a collection of related data. Each piece of data within the array is an element. The position of each element within the array is pointed to be its index. Arrays usually begin at index 0, not index 1.
You can also change the value of an element by using its index, like this
-
-
-
This will replace whatever was in position 4 in the MyArray array with "11". So we are replacing the number 7 with the number 11
FUNCTIONS
-
insert - insert an item at a specific location in the array, all the data above is moved up one location
delete - remove an item from a location, then all the data moves down one place.
-
slice - take a chunk of data out of an array to form a new array, the original array remains intact
Iteration
when you want to print every item in a long array, you could use a FOR loop(or any iteration loop)like:
-
-
-
Static Arrays
-
-
the program that the array named MyList requires enough memory to store five items. Even when it is empty of any elements or values, it is still given the same amount of memory.
Dynamic Arrays
-
A dynamic array grows and shrinks as items are added or removed from it using a pair of empty brackets.
run slightly slower than a static array and they use an unpredictable amount of memory - if they use too much, then the program crashes.
Two dimensional array
-
The pseudocode above is declaring a 2D array made up of 3 rows and 4 columns. A 2D array can be used to store tabular data very efficiently.
D array is ideal for storing any data that has been arranged in a grid - for example the computer screen you are reading right now is made up of pixels, and any pixel can be identified by its vertical and horizontal location.
SUMMARY
-
-
-
-
-
An array is usually made up of a single data type - number, string etc
-
-
-
-
-
-
-
INPUTTING- As the data is a list, an array should be used. And as the list is open-ended, a dynamic array should be used.
-