reating tree containers: one that uses a vector to hold your trees (class VectorContainer). Each of these container classes should be able to hold any amount of different expressions each of which can be of any size. see example. Please create vectorContainer.hpp all I need sort.hpp #ifndef __SORT_HPP__ #define __SORT_HPP__ #include "container.hpp" class Container; class Sort { public: /* Constructors */ Sort(); /* Pure Virtual Functions */ virtual void sort(Container* container) = 0; }; #endif //__SORT_HPP__ base.hpp #ifndef __BASE_HPP__ #define __BASE_HPP__ #include class Base { public: /* Constructors */ Base() { }; /* Pure Virtual Functions */ virtual double evaluate() = 0; virtual std::string stringify() = 0; }; #endif //__BASE_HPP__ container.hpp #ifndef __CONTAINER_HPP__ #define __CONTAINER_HPP__ #include "sort.hpp"

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

creating tree containers: one that uses a vector to hold your trees (class VectorContainer). Each of these container classes should be able to hold any amount of different expressions each of which can be of any size. see example.

Please create vectorContainer.hpp all I need

sort.hpp

#ifndef __SORT_HPP__
#define __SORT_HPP__

#include "container.hpp"

class Container;

class Sort {
public:
/* Constructors */
Sort();

/* Pure Virtual Functions */
virtual void sort(Container* container) = 0;
};

#endif //__SORT_HPP__

base.hpp

#ifndef __BASE_HPP__
#define __BASE_HPP__

#include <string>

class Base {
public:
/* Constructors */
Base() { };

/* Pure Virtual Functions */
virtual double evaluate() = 0;
virtual std::string stringify() = 0;
};

#endif //__BASE_HPP__

container.hpp

#ifndef __CONTAINER_HPP__
#define __CONTAINER_HPP__

#include "sort.hpp"
#include "base.hpp"

class Sort;
class Base;

class Container {
protected:
Sort* sort_function;

public:
/* Constructors */
Container() : sort_function(nullptr) { };
Container(Sort* function) : sort_function(function) { };

/* Non Virtual Functions */
void set_sort_function(Sort* sort_function); // set the type of sorting algorithm

/* Pure Virtual Functions */
// push the top pointer of the tree into container
virtual void add_element(Base* element) = 0;
// iterate through trees and output the expressions (use stringify())
virtual void print() = 0;
// calls on the previously set sorting-algorithm. Checks if sort_function is not null, throw exception if otherwise
virtual void sort() = 0;

/* Essentially the only functions needed to sort */
//switch tree locations
virtual void swap(int i, int j) = 0;
// get top ptr of tree at index i
virtual Base* at(int i) = 0;
// return container size
virtual int size() = 0;
};

#endif //__CONTAINER_HPP__

Example

#ifndef __LISTCONTAINER_HPP__
#define __LISTCONTAINER_HPP__

#include "container.hpp"
#include <list>
#include <iostream>
#include <stdexcept>
class Sort;

class ListContainer: public Container{
public:

std::list<Base*> baseList;

//Container() : sort_function(nullptr){};
//Container(Sort* function) : sort_Function(function){};

//void set_sort_funtion(Sort* sort_function){
// this -> sort_function = sort_function;
//}

void add_element(Base* element){
baseList.push_back(element);
}
void print(){
for(std::list<Base*>::iterator i = baseList.begin(); i != baseList.end(); ++i){
if(i == baseList.begin()){
std::cout <<(*i) -> stringify();
}
else{
std::cout << ", " << (*i) -> stringify();
}
}
std::cout << std::endl;
}
void sort(){
try{
if(sort_function != nullptr){
sort_function -> sort(this);
}
else{
throw std::logic_error("invalid sort_function");
}
}
catch(std::exception &exp){
std::cout << "ERROR : " << exp.what() << "\n";
}
}

//sorting functions

void swap(int i, int j){
std::list<Base*>::iterator first = baseList.begin();
for(int f = 0; f < i; f++){
first++;
}
Base* temp = *first;
std::list<Base*>::iterator second = baseList.begin();
for(int s = 0; s < j; s++){
second++;
}
*first = *second;
*second = temp;
}
Base* at(int i){
std::list<Base*>::iterator x = baseList.begin();
for(int a = 0; a < i; a++){
x++;
}
return *x;
}
int size(){
return baseList.size();
}
};
#endif //__LISTCONTAINER_HPP__

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education