Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have stack implementation adapted from a vector, how would I implement the move constructor and the move assignment operator .h code #ifndef STACK_H #define
I have stack implementation adapted from a vector, how would I implement the move constructor and the move assignment operator
.h code
#ifndef STACK_H | |
#define STACK_H | |
#include | |
#include | |
namespace COP4530 { | |
template | |
class Stack { | |
//friend functions | |
//invokes the print() method to print | |
template | |
friend std::ostream& operator<<(std::ostream&, const Stack | |
//returns true if the two compared stacks have the same elements, in the same order | |
template | |
friend bool operator==(const Stack | |
//returns true if every element in stack a is less than stack b | |
template | |
friend bool operator<=(const Stack | |
public: | |
//zero-argument constructor | |
Stack(); | |
//destructor | |
~Stack(); | |
//copy constructor | |
Stack(const Stack | |
//move constructor | |
Stack(Stack | |
//copy assignment operator | |
Stack | |
//move assignment operator | |
Stack | |
//returns true if the Stack contains no elements, and false otherwise | |
bool empty() const; | |
//delete all elements from the stack | |
void clear(); | |
//adds x to the stack (copy version) | |
void push(const T& x); | |
//adds x to the stack (move version) | |
void push(T && x); | |
//removes and discards the most recently added element of the stack | |
void pop(); | |
//mutator that returns a reference to the most recently added element of the stack | |
T& top(); | |
//accessor that returns the most recently added element of the stack | |
const T& top() const; | |
//returns the number of elements stored in the stack | |
int size() const; | |
//prints elements of stack with delimiter | |
void print(std::ostream& os, char ofc = ' ') const; | |
private: | |
std::vector | |
}; | |
#include "stack.hpp" | |
} | |
#endif |
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