Question: list these in the code: preconditions and postconditions for the functions; and state the efficiency Big O of each function. #include set.h using namespace std;
list these in the code:
- preconditions and postconditions for the functions; and
- state the efficiency Big O of each function.
#include "set.h"
using namespace std;
// postcondition: empty set has been created set::set(size_type initial_capacity) { data = new value_type[initial_capacity]; used = 0; capacity = initial_capacity; }
// postcondition: set has been deallocated set::~set() { delete data; }
// postcondition: a copy of source has been created set::set(const set& source) { capacity = source.capacity; used = source.used; //Resize data to source data resize(source.capacity); for(int i = 0; i < source.used; i++) { data[i] = source.data[i]; } } // precondition: // postcondition: set & set::operator = (const set& source) { // Check for self assignment if(this != &source) { this->used=source.used; this->data=source.data; } return *this; } // postcondition: entry is in the set void set::insert(const value_type & entry) { if(used>=capacity) { size_type newSize=capacity*1.5; capacity=newSize; } if(!contains(entry)) { data[used]=entry; used++; } } // postcondition: entry is not in the set void set::remove(const value_type& entry) { int count=0; int temp; for(int i=0; i void set::resize (unsigned int new_size) { value_type* temp = new value_type[new_size]; for(int i = 0; i < used; i++) { temp[i] = data[i]; } data = temp; capacity = new_size; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
