Page 20 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 20
Unit 1: Introduction to Data Structure and Arrays
We may continue this process to create a linked list of any number of values. Each time you need Notes
to store a value allocate the node and use it in the list. For example,
node2.next=&node3;
would add another link.
Also every list must have an end. This is necessary for processing the list. C has a special pointer
value called NULL that can be stored in the next field of the last node.
In the above two-node list, the end of the list is marked as follows:
node2.next=NULL;
The value of the value member of node2 can be accessed using the next member of node1 as
follows:
cout<<”\n”<<node1.next->value;
Task Write a syntax to represent a node.
1.6 Arrays Implementation
1.6.1 Array
A group of finite number of identical type of elements accessible by a common name. An array
has a name which is also the name of each of its elements. For example, let there be an array abc
of integers having 6 elements. The same is shown below.
The names of different elements are shown below.
abc[0] abc[1] abc[2] abc[3] abc[4] abc[5]
1.6.2 Index or Subscript
The integral value that corresponds to the ordinal position of an array element is called index or
subscript.
1.6.3 Dimensions of an Array
On the basis of the number of indices required to access a member element in an array, an array
can be classified into the following categories:
1. Single-dimensional Arrays
2. Multi-dimensional Arrays
Each type of Array has different kind of memory representation.
Memory Allocation to Arrays
Member elements of an array are provided contiguous memory locations. When a program
requests the operating system that it intends to create an array the operating system computes
the size of one element and multiplies the same with the number of elements requested to obtain
the total number of memory cells required. The operating system then allocates those many
LOVELY PROFESSIONAL UNIVERSITY 15