Random Access Data Structure
Programs define data structures in two basic systems: the linked list and the array. These two systems are the basis for more complicated structures. Of these systems, the array is better suited to random access.
-
Function
-
A basic array has one data type. Many instances of that data type are held together as a series of records. Each record is accessed directly by using an index. If a program needs to hold a number to use later, it puts it in a variable. With an array, many different numbers are held in the same variable. For example NumVar := 0, sets the value of the variable NumVar to zero. NumArr[5] := 0 puts a value in the fifth element of the array NumArr.
Features
-
The ability to jump directly to a named element in an array makes this data structure better suited to random access functions than a linked list. To reach element 5 of a linked list, the program has to pass through elements 1 to 4.
-
Structures
-
The basic array provides the foundation for more complicated structures: for example, a word (or "string") is an array of characters. A multi-dimensional is an array of arrays. Each element is accessible immediately by using indexes, making this data structure ideal for random access.
-