Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C++ to create a circular dynamic array Your dynamic array class should be called CDA for circular dynamic array. The CDA class should manage

image text in transcribed

image text in transcribed

image text in transcribed

Using C++ to create a circular dynamic array

Your dynamic array class should be called CDA for circular dynamic array. The CDA class should manage the storage of an array that can grow and shrink. The class should be implemented using C++ templates. As items are added and removed from both the front and the end of the array, the items will always be referenced using indices ...size-1. Your CDA class should include a flag indicating whether the array is in sorted order, or it is unordered. The public methods of your class should include the following (elmtype indicates the type from the template): Function Runtime 0(1) CDA(); CDA(int s); 0(1) -CDA(); elmtype& operator[](int i); O(1) 0(1) Description Default Constructor. The array should be of capacity 1 and ordered is false. For this constructor the array should be of capacity and sizes with ordered = false. Destructor for the class Traditional [] operator. Should print a message if i is out of bounds and return a reference to value of type elmtype stored in the class for this purpose. If the ordered flag is true, verify that any change in the array leaves it still ordered. If necessary set the ordered flag to false. increases the size of the array by 1 and stores v at the end of the array. Should double the capacity when the new element doesn't fit. If ordered is true, check to be sure that the array is still in order. increases the size of the array by 1 and stores v at the beginning of the array. Should double the capacity when the new element doesn't fit. The new element should be the item returned at index 0. If ordered is true, check to be sure that the array is still in order. reduces the size of the array by 1 at the end. Should shrink the capacity when only 25% of the array is in use void AddEnd(elmtype v); 0(1) amortized void AddFront(elmtype v); O(1) amortized void DelEnd(); 0(1) amortized void Del Front(); 0(1) amortized int Length(); int Capacity(); int Clear(); reduces the size of the array by 1 at the beginning of the array. Should shrink the capacity when only 25% of the array is in use after the delete. returns the size of the array. returns the capacity of the array. Frees any space currently used and starts over with an array of capacity 1 and size 0. Returns the status of the ordered flag. O(1) O(1) O(1) bool Ordered(); O(1) int SetOrdered(); | O(size) Elmtype Select(int k); O(1) or O(size) expected Check to see if the array is in order. Set the order flag appropriately. Return 1 if the array was ordered and -1 otherwise. returns the kth smallest element in the array. If ordered is true then return the item at index k-1. Otherwise use the quickselect algorithm. Quickselect should choose a random partition element. Performs insertion sort on the array. Sets ordered to true. Sorts the values in the array using the quick sort algorithm. This should pick the partition value using the median of three technique. Set ordered to true. Should also make use of insertion sort to improve performance. Void InsertionSort() void QuickSort(); O(size*size) worst case O(size * size) worst case O(size lg size) expected void CountingSort(int m); O(size * m) int Search(elmtype e) Sorts the values in the array using counting sort, where the values in the array are in the range 0...m. Set ordered to true. If ordered is true, perform a binary search of the array looking for the item e. Otherwise perform linear search. Returns the index of the item if found or -1 otherwise. O(lg size) or O(size) Your class should include proper memory management, including a destructor, a copy constructor, and a copy assignment operator. Your dynamic array class should be called CDA for circular dynamic array. The CDA class should manage the storage of an array that can grow and shrink. The class should be implemented using C++ templates. As items are added and removed from both the front and the end of the array, the items will always be referenced using indices ...size-1. Your CDA class should include a flag indicating whether the array is in sorted order, or it is unordered. The public methods of your class should include the following (elmtype indicates the type from the template): Function Runtime 0(1) CDA(); CDA(int s); 0(1) -CDA(); elmtype& operator[](int i); O(1) 0(1) Description Default Constructor. The array should be of capacity 1 and ordered is false. For this constructor the array should be of capacity and sizes with ordered = false. Destructor for the class Traditional [] operator. Should print a message if i is out of bounds and return a reference to value of type elmtype stored in the class for this purpose. If the ordered flag is true, verify that any change in the array leaves it still ordered. If necessary set the ordered flag to false. increases the size of the array by 1 and stores v at the end of the array. Should double the capacity when the new element doesn't fit. If ordered is true, check to be sure that the array is still in order. increases the size of the array by 1 and stores v at the beginning of the array. Should double the capacity when the new element doesn't fit. The new element should be the item returned at index 0. If ordered is true, check to be sure that the array is still in order. reduces the size of the array by 1 at the end. Should shrink the capacity when only 25% of the array is in use void AddEnd(elmtype v); 0(1) amortized void AddFront(elmtype v); O(1) amortized void DelEnd(); 0(1) amortized void Del Front(); 0(1) amortized int Length(); int Capacity(); int Clear(); reduces the size of the array by 1 at the beginning of the array. Should shrink the capacity when only 25% of the array is in use after the delete. returns the size of the array. returns the capacity of the array. Frees any space currently used and starts over with an array of capacity 1 and size 0. Returns the status of the ordered flag. O(1) O(1) O(1) bool Ordered(); O(1) int SetOrdered(); | O(size) Elmtype Select(int k); O(1) or O(size) expected Check to see if the array is in order. Set the order flag appropriately. Return 1 if the array was ordered and -1 otherwise. returns the kth smallest element in the array. If ordered is true then return the item at index k-1. Otherwise use the quickselect algorithm. Quickselect should choose a random partition element. Performs insertion sort on the array. Sets ordered to true. Sorts the values in the array using the quick sort algorithm. This should pick the partition value using the median of three technique. Set ordered to true. Should also make use of insertion sort to improve performance. Void InsertionSort() void QuickSort(); O(size*size) worst case O(size * size) worst case O(size lg size) expected void CountingSort(int m); O(size * m) int Search(elmtype e) Sorts the values in the array using counting sort, where the values in the array are in the range 0...m. Set ordered to true. If ordered is true, perform a binary search of the array looking for the item e. Otherwise perform linear search. Returns the index of the item if found or -1 otherwise. O(lg size) or O(size) Your class should include proper memory management, including a destructor, a copy constructor, and a copy assignment operator

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

What changes, if any, are projected for this environment?

Answered: 1 week ago

Question

How have these groups changed within the last three years?

Answered: 1 week ago