Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++, you are implementing the vector class in the VectorStub zip. You need to implement all of the methods, and that's it. You cannot

In C++, you are implementing the vector class in the VectorStub zip. You need to implement all of the methods, and that's it. You cannot add any new properties. Your solutions must conform to the Big O notations next to each method.

A few things to remember about templates:

  1. All the code is in the h file
  2. When testing a template, any method you don't call gets deleted. So make sure you test them all, or you might secretly have one that doesn't compile.
  3. If you make your Vector not a template (change all the T's to int or something) it becomes easy to test as long as you remember to re-template it. (VS has trouble autocompleting a template since the code doesn't exist yet.)
  4. I'm going to drop your vector in to my project, so don't bother changing main unless you want to test something differently.

The hard part of this is the memory management, so take special care with Reserve, the constructors, and the destructor.

Vector.h // I am going to match the names that STL uses so you don't get confused in the real world. I'm skipping operator [] for a specific reason that // doesn't come up for a few weeks.

template class Vector { T* mData; int mSize; int mCapacity;// For testing purposes, initialize this to 15. Whenever you allocate new memory, double it.

T mUndefined;// Lots of STL functions say that doing something naughty gets "undefined behavior". It could throw, crash, make you eggs, or return nonsense. // Return this undefined one if anybody ever tries to go out of bounds.

public: Vector()// O(1) { mSize = 0; mData = nullptr; } Vector(const Vector& tOther) : Vector()// O(n) { } Vector &operator =(const Vector& tRHS)// O(n) { return *this; // This line is weird so I'm just giving it to ya. It's just the definition of an = } void PushBack(const T &tItem)// O(1) { // We take a const reference, but we _copy_ it in to our personal array. } void PopBack()// O(1) { } void PushFront(const T &tItem)// O(n) { } void PopFront()// O(n) { } T& At(int tWhere)// O(1) { return mUndefined; } void Erase(int tWhere)// O(n) { // Keep an eye on this one. We'll change its prototype next week } void Insert(int tWhere, const T& tWhat)// O(n) { // Keep an eye on this one. We'll change its prototype next week } void Clear()// O(1) { } int Size()// O(1) { return 0; } void Reserve(int tCount)// O(n) { } int Capacity()// O(1) { return 0; } };

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago