One dimensional array It Is An Ordered List , Which Consist Of A Fixed Number Of Homogeneous Data Items (Elements).An Array Is A Primitive Data Structure. These Elements Are Stored In Successive Memory Locations According To Size Of Data Type. Array Is Also Referred As Set Of (Index , Value).
CONCEPT STRUCTRE 10 5 46 2 100 97 ... A[0] A[1] A[2] A[3] A[4] A[5] A[MAX -1] (index) Data element value
INSERT OPERATION The Insert Operation Is Performed By Shifting All The Elements One Position Ahead From Index i To N-1 Where i Is The Specified Index For New Element Is To Be Inserted. And Adding The New Element To The Array At The Specified Index Position.
For example, index for insertion is i =2 and new element is 17 with N=6. the MAX is the size of the array A. Array before insertion : 10 5 46 2 100 97 … A[0] A[1] A[2] … A[MAX-1] A[N-1] Insert index position 10 5 46 2 100 97 … A[0] 1 2 3 4 5 A[6] A[MAX-1] Insert Index Position Move All Elements From Insert Index Position I N-1 Towards Right By One Position
Array After Shifting: 10 5 46 46 2 100 97 … A[0] 1 2 3 4 5 A[6] A[MAX-1] Insert index position Shifted elements
10 5 17 46 2 100 97 … A[0] 1 2 3 4 5 A[6] A[MAX-1] Array After Insertion: Now, insert (store) new data element 17 at given index position 2: Inserted element For Every New Element Inserted The Number Of Elements I.E N Should Be Incremented By 1. If N= Max-1 Then Array Is Full And Insertion Operation Cannot Be Performed As There Is No Space For New Element In The Array.
Delete operation The delete operation will delete the element at specified element index from one-dimensional array. The deletion operation performed by shifting all the elements one position before from index i =1 to N- 1 where i is the index of element to be deleted. A[ i ] = A[i+1], for all i to N-1 . This shifting causes overwriting of the said element with element at next index position.
For example, For an array N=7 and index position for deletion is i =3 and maximum array size as MAX. Array Befor e Deletion: 10 5 17 46 2 100 97 … A[0] 1 2 3 4 5 A[6] A[MAX-1] Delete Index Position Now , Shift All Element From Index 4 To 6 One Position Before As Below: 10 5 17 46 2 100 97 … A[0] 1 2 3 4 5 A[6] A[MAX-1] Element At Index 3 The Array After The Shifting Backward Is:
Array after deletion: 10 5 17 2 100 97 97 … A[0] 1 2 3 4 A[5] A[MAX-1] Last element of array The element 46 is deleted from the array. After every delete operation the number of elements N should be decrement by 1. if array is empty , the deletion operation cannot be performed .