Question
Using C++, implement an efficient template operator - function that takes two pre-sorted Vectors called v1 and v2 which are provided as parameters to the
Using C++, implement an efficient template operator- function that takes two pre-sorted Vectors called v1 and v2 which are provided as parameters to the operator. The operator function returns a Vector that has all the elements of v2 that are common in v1 removed from v1. The following usage is anticipated where v3 is another Vector. The Vector class to be used is from your own. You have shown this at an earlier question. STL data structures or algorithms or other library routines cannot be used in this question.
v3 = v1 - v2;
As an example, if Vector v1 contains (2, 8, 12 17, 22), v2 contains (17, 18, 22, 30), after the above line of code, v3 will contain (2, 8, 12). Vectors v1 and v2 contain sorted data and must not be modified. Vector v3 remains sorted. Make sure your code works when tested in Codeblocks.
I have done some parts, something like
template
void operator(vector
template
void operator(vector
{
int i=0, j=0;
T num1=v1.at(0);
T num2=v2.at(0);
while(i { num1 = v1.at(i); num2= v2.at(j); if(num1 { v3.push_back(num1); i++; } else if(num2 < num1) { j++; } else { i++; j++; } while(i { v3.push_back(v1.at(i++)); } } } But not working....Could you please help me to figure out what to do? We use C++ ISO (std=++11) compiler only and below is my Vector class #ifndef Vector_h #define Vector_h #include using namespace std; template class Vector { public: Vector(); ~Vector(); void push_back(const T& i); T& at(int i); void resize(int newSize); int size(); private: int length; int arr; T *list; }; template template
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started