Static Array Class

Learn to implement an array class and its methods.

Challenge

Write a program to create a class called array. Make a provision to perform the following operations on objects of this class:

Display: Prints all elements of an array

Search: Finds the location of an element with a given value

Insertion: Adds a new element to an array. This would shift the elements to the right. If some element already exists on the specified index, then the method should simply shift it to the right and insert a new element at that index.

Deletion: Removes an element from an array using its position. This would shift the elements to the left and set 0 in the place of a deleted element.

Reverse: Reverses the elements of an array

Sample run

Here’s what you should see when you run the program.

Elements of Array: 
11  12  13  14  15

After deletion: 
11  13  14  0  0

After insertion: 
11  222  13  14  555

After reversing: 
555  14  13  222  11

The element 222 is present at 4th position

The element 666 is not present in the array

Coding exercise

Your job is to define the constructors and methods outside the array class given below.

Get hands-on with 1200+ tech skills courses.