Page 17 - DCAP407_DATA_STRUCTURE
P. 17
Data Structure
Character is used for character values. It is denoted as Char. The standard type CHAR consists of a set
of printable characters. The type CHAR comprises 26 upper-case letters, 26 lower-case letters, 10
decimal digits, and a number of other graphic characters such as, punctuation marks. The subsets of
letters and digits are structured and contiguous. Every single computer stores character data in a one
byte field as an integer value. A byte consists of 8 bits so the one byte field has 256 possibilities using the
positive values of 0 to 255.
The type Boolean is used for Boolean values. The standard type BOOLEAN values are denoted by the
two identifiers TRUE and FALSE. The Boolean operators comprise logical conjunction, disjunction, and
negation. The logical conjunction is denoted by the symbol &, the logical disjunction by OR, and
negation by “~”.
Based on the language and its implementation, primitive data types may or may not
have a one-to-one connection with objects in the computer's memory.
1.3.2 Non-primitive Data Structure
Non-primitive data structures are those that are derived from primitive data structures. These data
structures cannot be operated or manipulated directly by the machine level instructions. They focus on
formation of a set of data elements that is either homogeneous (same data type) or heterogeneous
(different data type). These are further divided into linear and non-linear data structure based on the
structure and arrangement of data.
Linear Data Structure
A data structure that maintains a linear relationship among its elements is called a linear data structure.
Here, the data is arranged in a linear fashion. But in the memory, the arrangement may not be
sequential.
Arrays, linked lists, stacks, queues.
Array
Array, in general, refers to an orderly arrangement of data elements. Array is a type of data structure
that stores data elements in adjacent locations. Array is considered as linear data structure that stores
elements of same data types. Hence, it is also called as a linear homogenous data structure.
When we declare an array, we can assign initial values to each of its elements by enclosing the values in
braces { }.
int Paul [5] = { 26, 7, 67, 50, 66 };
This declaration will create an array as shown below:
0 1 2 3 4
Paul
26 7 67 50 66
The number of values inside braces { } should be equal to the number of elements that we declare for the
array inside the square brackets [ ]. In the example of array Paul, we have declared 5 elements and in
the list of initial values within braces { } we have specified 5 values, one for each element. After this
declaration, array Paul will have five integers, as we have provided 5 initialization values.
Arrays can be classified as one-dimensional array, two-dimensional array or multidimensional array.
1. One-dimensional Array: It has only one row of elements. It is stored in ascending storage location.
2. Two-dimensional Array: It consists of multiple rows and columns of data elements. It is also
called as a matrix.
10 LOVELY PROFESSIONAL UNIVERSITY