Tech Tuesday: Data Structures (Arrays)

If you have been a faithful reader of Tech Tuesday, you may be asking yourself just how many more posts on Data Structures could possibly be coming up as this is now the sixth such post (including the introduction).  The answer is that after today there will be at least one more before moving on to a different subject for now.  But that’s not for a lack of material – there is always more to say about data structures.  And if nothing else one important takeaway from these posts should be that understanding the keywords of a programming language is only a tiny part of what it takes to be effective at programming.

The posts so far have dealt with data structures that let us combine different attributes into a single thing (structs, maps, JSON, objects).  But what if we have many of the same thing?  Keeping with our canonical example the point.  What data structure can we use to keep track of many points?  In the examples so far we used two separate variables to hold our point A and point B.  What if we had a 1,000 points that together make up an image of size 20 x 50?  Using 1,000 different variables would be incredibly cumbersome.

Instead, most programming languages (but not all) have built in support for arrays.  We already encountered a version of the array in the post on maps, which are also known as associative arrays.  But what we are interested in now are arrays that use integers as indices and can be multidimensional as in the following example, which makes a 20 x 50 image of random colors with each color represented by a value between 0 and 255:

Loading...
highlight
Collect this post to permanently own it.
Continuations logo
Subscribe to Continuations and never miss a post.
#tech tuesday#programming#data structures#arrays