Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedIn 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 following class definition, supplying definitions for the the various member functions, and adding whatever private members you need.

class ordered-array public: * constructor Construct a new ordered-array with the given capacity (naxinun size) The size of a new ordered-array should be 8. ordered-array(int cap); // destructor ordered-array); * size() Returns the size (number of elements in the array). int size(); /*capacity Returns the maxinum size of the array. int capacity); /* insert(e) Insert e into the array. If size)capacity() then this does nothing. Note that it is OK to insert duplicates; if n copies of a value are inserted into the array then n copies should appear in the array void insert(int elen); /* remove(e) Remove e from the array, if it exists. (If it does not exist, the array should be unchanged.) If multiple copies of e are present, only one should be removed. void renove(int elen); /* exists(e) Returns true if e is present at least once in the array. bool exists(int elen); * begin() Retuen apeinter to the tirst elenent of the array, The value pointed to by this should be the snallest element in the array (if the array is not enpty) int* begin(); /* end() Re turns a pointer to one-past-the-end (ast 1) elenent of the array. This should ignore any "unused" elenents past the end of the array, i.e., > size but

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions