Problem Statement
Why construct an Array?
Before you start solving array problems. Understanding and implementing an array-like data structure is a good practice.
This lesson teaches you how to implement common array operations, such as inserting an element, removing an element, getting an element, finding the length of the array, and printing its elements.
What are we building?
As discussed above, we are going to build an array from scratch that contains some of the most common array operations.
We will also learn how to convert the fixed-size array into a dynamic array by tweaking a method. This is the concept of dynamic arrays: LinkedList
, ArrayList
, and a few more complex data structures.
Problem statement
Build an array from scratch and store elements in it. The array should allow inserting, deleting, getting, and printing elements.
Input:
CREATE -> 10 // create an array with capacity 10
INSERT -> {1, 2, 3, 4, 5} // insert these elements
DELETE -> 2 // remove 2nd index element
GET -> 0 // print 0th element
SIZE -> `.size()` // should print how many items currently an array has
PRINT -> // print all elements shown in output
Output:
{1, 2, 4, 5, 0, 0, 0, 0, 0, 0}
Note: Every software requirement should be broken into smaller chunks. It will be easy to build smaller parts and combine them to complete the requirement.