DS Deletion Operation

Deletion Operation

Deletion refers to removing an existing element from the array and re-organizing all elements of an array.

Example

Consider LA is a linear array with N elements and K is a positive integer such that K<=N.

//Write a program to perform deletion operation.
#include <stdio.h>
void main()
{
   int LA[] = {2,4,6,8,9};
   int k = 3, n = 5;
   int i, j;

   printf("The original array elements are:n");

   for(i = 0; i<n; i++)
   {
      printf("LA[%d] = %d n", i, LA[i]);
   }

   j = k;

   while( j < n)
   {
      LA[j-1] = LA[j];
      j = j + 1;
   }

   n = n -1;

   printf("The array elements after deletion:n");

   for(i = 0; i<n; i++)
   {
      printf("LA[%d] = %d n", i, LA[i]);
   }
}

Output:

Command Prompt
The original array elements are:
LA[0]=2
LA[1]=4
LA[2]=6
LA[3]=8
LA[4]=9
The array elements after deletion:
LA[0]=2
LA[1]=4
LA[2]=8
LA[3]=9


Share This Page to Download:

Share to Download

Share This Page on:


Ask Question