Application of Arrays

Whenever we require a collection of data objects of the same type and want to process them as a single unit, an array can be used, provided the number of data items is constant or fixed. Arrays have a wide range of applications ranging from business data processing to scientific calculations to industrial projects.

Implementation of a Static Contiguous List

A list is a structure in which insertions, deletions, and retrieval may occur at any position in the list. Therefore, when the list is static, it can be implemented by using an array. When a list is implemented or realized by using an array, it is a contiguous list. By contiguous, we mean that the elements are placed consecutively one after another starting from some address, called the base address. The advantage of a list implemented using an array is that it is randomly accessible. The disadvantage of such a list is that insertions and deletions require moving of the entries, and so it is costlier. A static list can be implemented using an array by mapping the ith element of the list into the ith entry of the array, as shown in following Figure.

A complete C program for implementing a list with operations for reading values of the elements of the list and displaying them is given here:

int main()
   void read(int *,int);
   void dis(int *,int);
   int a[5],i,sum=0;

   printf("Enter the elements of array \n");
   read(a,5);      /*read the array*/
   printf("The array elements are \n");
   return 0;

void read(int c[],int i)
   int j;

void dis(int d[],int i)
   int j;
      printf("%d ",d[j]);

You may also like...