Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create C++ minimize member function for a dynamic sequence container that is implemented using an array. Member variables include the array itself, the size of

  1. Create C++ minimize member function for a dynamic sequence container that is implemented using an array. Member variables include the array itself, the size of the array and the current number of items stored in the array. The function should insure that there is no dynamic memory being wasted by empty array elements.
  2. Write a function implementation that overloads the == operator of a dynamic array sequence (sequence2) container class to test if two object have the same data sets. The sequence class is similar to the bag, except that the order of the items should not be modified.
  3. Write efficient member functions for the following operations (include documentation):
    • delete the first element from a dynamic array.
    • delete the last element from a dynamic array.
  4. Implement the following function. Make sure you have no memory leaks.
  1. //Precondition: olda is a dynamic array
  2. //Postcondition: The array at olda is replaced with a new array that contains
  3. //ONLY the EVEN indexed values in its most minimal usage of memory. For
  4. //example, index's 0,2,4, and so on will exist in the new array and 1 and 3
  5. //will be discarded. The new array will be about half the size of original.
  6. //The number of items removed from the array is returned.

size_t reduceEven(double*& olda, const size_t& size);

  1. Implement the following function. Make sure you have no memory leaks.
  1. //Precondition: array points to dynamic array of char with a physical size // of count.
  2. //Postcondition: appends a copy of the string passed as a parameter,
  3. // into the back of the array. count is updated with the new physical // size of the array.

void append(char*& array, size_t& count, const string& s);

  1. What is the big O of the following code snippet in terms of n when n > 0? Note: there is not a worst or best case for this code. Show evaluations of a few ns to loosely prove your answer for full credit.
  1. for ( size_t i=n - 1 ; i > 0 ; --i)
  2. for ( size_t j=0 ; j < n ; ++j)

//work here of constant time

  1. Implement the following function. Make sure you have no memory leaks.
  1. //Precondition: data points to an array of count items, or null when
  2. // count is 0.
  3. //Postcondition: All indexes where the data is odd will be removed
  4. // from the array. The physical size of the array is reduced and
  5. // data pointer is updated. The new size of the array is returned.
  6. // No memory leaks.

size_t removeOdds(int*& data, size_t count);

  1. Overload the << operator on the bag2 class, assuming the value_type is string, we should get the following. Make sure you have no memory leaks.
  1. bag b;
  2. b.insert(string1);
  3. b.insert(string2);
  4. b.insert(string3);

cout << b;

Would output:

[string1, string2, string3]

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions