2 Static arrays: Building your first data structure
In this chapter
- You get familiar with a few basic ideas in data structures.
- You learn about a fundamental data structure, arrays.
- You learn about the difference between statically-sized and dynamically-sized arrays.
- You learn about the typical operations you can do on arrays.
- Finally, you learn why keeping your array’s elements in order makes a difference, and how this changes the way you perform those operations on the array.
With this chapter, we begin to talk about how data structures work and how to implement them. This chapter is special in that it will gently introduce you to the process we will follow throughout the book as we talk about the technology we are introducing. But it will also introduce you to some basic concepts that you will need for the rest of the book.
What is an array?
We will begin our journey into the land of data structures with arrays, specifically static arrays. Arrays organize data by holding a collection of elements and making them accessible through an index.
But right now the most important question we want you to be able to answer is: why arrays? Let me try to explain this with an example.
Memory and drawers
First, we need to take a step back and talk about how memory is organized. For the sake of simplicity, I like to think of memory as a modular shelf that can hold drawers.
