Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make correction where there are errors PLEASE This is a complete implementation of the LargeType class, the insertionSort function, and the main function as described

Make correction where there are errors PLEASE This is a complete implementation of the LargeType class, the insertionSort function, and the main function as described in the problem statement. However, the LargeTypeRaw class and the timing experiments are not included. To complete the solution, I you would need to implement the LargeTypeRaw class, including the big 5 methods (he copy constructor, move constructor, copy assignment operator, move assignment operator, and destructor, To implement these methods, you would need to use dynamic memory allocation and deallocation, and handle any potential errors that may occur. Be sure to test the LargeTypeRaw class by running code that calls all methods of the big 5), and the code does not include any timing experiments, but you would need to add them to complete the solution. You would need to use a library such as std::chrono to measure the performance of the insertionSort function on both LargeType and LargeTypeRaw. You would need to test both on a vector size of 50,000, and report the time taken for sorting as a comment at the top of the source code file. You can also use other libraries such as dime if you want. Don't forget to include comments in all the code please.
 #include  #include  #include  #include  template  class LargeType { public: explicit LargeType(int size = 10) : data(size) {} int getSize() const { return data.size(); } bool operator<(const LargeType& rhs) const { return getSize() < rhs.getSize(); } private: std::vector data; }; template  class LargeTypeRaw { public: LargeTypeRaw(int size = 10) : data(new T[size]), size(size) {} LargeTypeRaw(const LargeTypeRaw& other) : data(new T[other.size]), size(other.size) { std::copy(other.data, other.data + size, data); } LargeTypeRaw(LargeTypeRaw&& other) noexcept : data(other.data), size(other.size) { other.data = nullptr; other.size = 0; } LargeTypeRaw& operator=(const LargeTypeRaw& other) { if (this != &other) { T* newData = new T[other.size]; std::copy(other.data, other.data + other.size, newData); delete[] data; data = newData; size = other.size; } return *this; } LargeTypeRaw& operator=(LargeTypeRaw&& other) noexcept { if (this != &other) { delete[] data; data = other.data; size = other.size; other.data = nullptr; other.size = 0; } return *this; } ~LargeTypeRaw() { delete[] data; } int getSize() const { return size; } bool operator<(const LargeTypeRaw& rhs) const { return getSize() < rhs.getSize(); } private: T* data; int size; }; template  void insertionSort(std::vector& vec) { for (int i = 1; i < vec.size(); i++) { T key = vec[i]; int j = i - 1; while (j >= 0 && vec[j] > key) { vec[j + 1] = vec[j]; j--; } vec[j + 1] = key; } } int main() { std::vector> vec; for (int i = 0; i < 50'000; i++) { int size = rand() % 10; vec.push_back(LargeType{size}); }

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

More Books

Students also viewed these Databases questions

Question

Explain how cultural differences affect business communication.

Answered: 1 week ago

Question

List and explain the goals of business communication.

Answered: 1 week ago