Array ADT
Implementation of append, insert, delete and display function in an array.
Creating a Structure for Array
The following Array structure has three key elements to it:
The actual array
An integer to store the length of the array (No. of elements present)
An integer to store the size of an the array (Maximum capacity)
Appending to the End
For appending an element to the end of an array, we need to first increment the length of the array and then store the desired value in the last index of array. This can be implemented using the following C code :
Inserting at a Specific Index
To insert an element at a particular index in the array, we must check if there's enough space in the array and then shift all the elements to the right of desired index by 1. This creates a space for the element to be inserted at the desired index. Function for the same :
Deleting from Specific Index
In this operating, the index of the element which needs to be deleted will be passed along with the array. To perform this operation, all the elements which are present after the index from which an element was deleted should be shifted left by 1 and length of array must be decremented.
Contributed by Nitin Ranganath
Last updated