Question
[c++] In this assignment, youll implement a simple data structure which maintains a sorted array . This is essentially just a simple wrapper around a
[c++]
In this assignment, youll implement a simple data structure which maintains a sorted array. This is essentially just a simple wrapper around a dynamically-allocated array of int (you can also use a vector) which allows the user to insert and remove values. The elements of the array should always be sorted in ascending order; this means that when you add new elements, you need to figure out where they go in the array, shift everything after them up, and then drop the new element into place. Likewise, when you remove an element, you have to find it, and then shift everything after it down.
The ordered_array has a maximum size known as its capacity which is specified when it is created, and fixed from that point forward. This is the maximum number of elements that can be insert-ed into the array, if none are remove-d, before the array is full. The number of elements currently in the array is its size. Member functions .size() and .capacity() provide access to both these values. Note that an arrays size is always 00 and its capacity. The size of an ordered array should be 0 when it is first created.
Use the above class definition, supplying definitions for the various member functions, and adding whatever private members you need.
You should place this class definition in a header file named ordered_array.hpp. Your method implementation (if not part of the class definition) should be in ordered_array.cpp. You can write your entire class definition in the header, if you want, or do the old-fashioned thing and write only the method declarations in the header, and put their implementations in a .cpp file.
In the comments before insert(), remove(), and exists(), try to answer the following question:
- If size() == n for some unknown n, approx. how much time will the method take, in terms of n? For example, if a method examines each element of the array twice, you might say it will take roughly 2n time to run.
Explain and justify your answers.
#includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started