Abstract Data Type-Array
Abstract Data Type-Array
An implementation of ADT consists of storage structures to store the data items and
algorithms for basic operation. All the data structures i.e. array, linked list, stack, queue
etc are examples of ADT.
Array
The simplest type of data structure is a linear (or one dimensional) array. A list of a
A 1, A 2, A 3 . . . . A n
C programming language provides a data structure called the array, which can store a
fixed-size sequential collection of elements of the same type. An array is used to store a
collection of data, but it is often more useful to think of an array as a collection of
variables of the same type. Instead of declaring individual variables, such as number0,
number1, ..., and number99, you declare one array variable such as numbers and use
numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A
specific element in an array is accessed by an index.
All arrays consist of contiguous memory locations. The lowest address corresponds to
the first element and the highest address to the last element.
One-Dimensional Array
In Pascal language we can define array as
VAR X: array [ 1 N] of integer {or any other type}
Thats means the structure contains a set of data elements, numbered (N), for example
called (X), its defined as type of element, the second type is the index type, is the type of
values used to access individual element of the array, the value of index is
1<= I =< N
By this definition the compiler limits the storage region to storing set of element, and the
first location is individual element of array , and this called the Base Address, lets be as
500. Base Address (501) and like for the all elements and used the index I, by its value
are range
1<= I =>N
According to Base Index (500), by using this relation:
Location ( X[I] ) = Base Address + (I-1)
When the requirement to bounding the forth element (I=4):
Location ( X[4] ) = 500 + (4-1)
= 500 +3
= 503
So the address of forth element is 503 because the first element in 500.
When the program indicate or dealing with element of array in any instruction like
(write (X [I]), read (X [I] ) ), the compiler depend on going relation to bounding the
requirement address.
Two-Dimensional Arrays
The simplest form of the multidimensional array is the two-dimensional array. A
twodimensional array is, in essence, a list of one-dimensional arrays. To declare a twodimensional integer array of size x,y you would write something as follows:
type arrayName [ x ][ y ]; Where type can be any valid C data type and arrayName will
be a valid C identifier. A two-dimensional array can be think as a table which will have