Arrays
Let’s start with an array, which was the main topic of Chapter 3, Arrays and Sorting. You can use this data structure to store many data of the same type, such as int
, string
, or a user-defined class. The important assumption is that the number of elements in an array cannot be changed after initialization. Moreover, arrays belong to random access data structures. This means that you can use indices to get access to the first, the middle, the n-th, or the last element from the array.
You can benefit from a few variants of arrays – namely, single-dimensional, multi-dimensional, and jagged arrays, also referred to as an array of arrays. All of these variants are shown in the following illustration:

Figure 10.2 – Variants of arrays
There are a lot of applications for arrays and, as a developer, you have probably already used this data structure many times. In this book, you saw how you can use it to store various data, such as the names of months, the multiplication table, or even a map of a game. In the last case, you created a two-dimensional array with the same size as a map, where each element specified a certain type of terrain, such as grass.
There are many algorithms that perform operations on arrays. However, one of the most common tasks is sorting an array to arrange its elements in the correct order, either ascending or descending. This book focuses on seven algorithms, namely selection sort, insertion sort, bubble sort, merge sort, Shell sort, quicksort, and heap sort. Each of them was described and presented in the illustration, as well as written in the C# code, together with a detailed explanation.