Algorithm For Deletion an Element in The Array With Program

Errorlogger
1

Deletion (LA, N, K, Item)

In this we have array LA specify the Linear Array with N element we want to delete an element from Kth position.

Algorithm for Deletion an Element in The Array

  1. Set Item: = LA[K]
  2. Repeat for J: = K to N - 1 set LA[J]: = LA[J + 1] (end of loop)
  3. Set N: = N - 1
  4. Exit 

Write a program to perform insertion operation from the array.

#include <stdio.h>
void main()
{
      int a[10], i, n, item, k;
      printf("Enter the range of the array = ");
      scanf("%d", &n);
      printf("Enter array's element's = ");
      for(i = 0; i < n; i ++)
      {
             scanf("%d", &a[i]);
      }
      printf("Enter the position from where you want to delete = ");
      scanf("%d", &k);
      item = a[k];
      for(i = n; i < n - 1; i ++)
      {
             a[i] = a[i + 1];
      }
      n = n - 1;
      printf("Delete element = %d", item);
      printf("Array's element's = ");
      for(i = 0; i < n; i ++)
      {
             scanf("%d\t", a[i]);
      }
}

Deletion:- It is the process in which we delete an element from the array. We have an array with N element. We want to delete the element from the Kth position of the array. First of all we assign the value of Kth element  to the item variable. Then we have to move all the elements from Kth + 1 position to the last position one step backward because the index number always represented by consecutive integer number after that the value of N (Number of element in the array) will be decrease by one because we have deleted an element from the array.

Post a Comment

1Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete
Post a Comment

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !