In the above example, create a class Array which contains two properties i.e. length and data, where length will store the length of an array and data is an object which is used to store elements.
Function in Array: There are many functions in array which are listed below:
Push(element): This function is used to push an element at the end of the array.
Pop(): It is used to delete an element at the end of the array.
In the above example, item variable will store the last element from data object and perform deletion of last element and then, it will decrease the length of by 1 and return the object.
insertAt(): This function is used to insert an element at given index.
This function accepts two parameters item and index. Index number denoting the place where data to be inserted and item is the value which is to be inserted at index.
deleteAt(index): This function is used to remove an element at given index or property in a data object.
In above function, use loop to reach at index till the end, and copy the next element at index and at the end of loop two copies of last element exist, delete last element through delete operator.
getElementAtIndex(index): It returns the element at given index.
Example: This function describes the implementation of array class and its various operations.
- Queue | Set 1 (Introduction and Array Implementation)
- Binary Tree (Array implementation)
- Implementation of Dynamic Array in Python
- Prefix Sum Array - Implementation and Applications in Competitive Programming
- Find the smallest positive number missing from an unsorted array : Hashing Implementation
- Array class in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.