Arrayoperation (Insertion, Deletion)
Arrayoperation (Insertion, Deletion)
ON
ARRAY OPERATION
ambuddha Chakraborty
ONE DIMENSIONAL
ARRAY
It Is An Ordered List, Which
Consist Of A Fixed Number Of
Homogeneous Data Items
(Elements). 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
(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.
Move All Elements From Insert Index Position I N-1 Towards Right By One
Position
A[0] 1 2 3 4 5 A[6]
A[MAX-1]
10 5 46 2 100 97 …
A[0] 1 2 3 4 5 A[6]
A[MAX-1]
10 5 46 46 2 100 97 …
Insert index
position
Shifted elements
Array After Insertion:
Now, insert (store) new data element 17 at given index
position 2:
A[0] 1 2 3 4 5 A[6]
A[MAX-1]
10 5 17 46 2 100 97 …
Inserted element
Element At Index 3
The Array After The Shifting Backward Is:
rray after deletion:
A[0] 1 2 3 4 A[5]
A[MAX-1]
10 5 17 2 100 97 97 …
Last element of
array