السلام عليكم
في الحقيقة لدي سؤال ولكن لم افهم ماهو المطلوب واتمنى الحصول على الاجابه ومساعدتي
عندي برنامج عن trees
// main.cpp : Defines the entry point for the console application.
#include
#include "bst.h"
using namespace std;
int main(int argc, char* argv[])
{
bst* tree = new bst();
int* x = NULL;
while(true){
cout << "Please enter a number(-1 to exit): ";
x = new int;
cin >> *x;
if(*x == -1) break;
tree->insert(new comparable(x));
cout << "The elements in the tree are:";
tree->printAscending(cout);
}
return 0;
}و
#ifndef _CONTAINER_H_
#define _CONTAINER_H_
#include
#include "comparable.h"
using namespace std;
template
class container {
public:
container();
virtual ~container();
virtual void insert(comparable* item) = 0;
virtual void printAscending(ostream&) = 0;
};
template
container::container(){}
template
container::~container(){}
#endif //_CONTAINER_H_و
#ifndef _COMPARABLE_H_
#define _COMPARABLE_H_
#include
using namespace std;
template
class comparable{
friend ostream& operator<<(ostream&, comparable*);
public:
comparable(t*);
~comparable();
bool operator<(const comparable&) const;
bool operator>(const comparable&) const;
bool operator==(const comparable&) const;
t* getData() const;
private:
t* data;
};
template
ostream& operator<<(ostream& out, comparable* c){
out << *c->data << ' ';
return out;
}
template
comparable::comparable(t* item){
data = item;
}
template
comparable::~comparable(){
}
template
bool comparable::operator <(const comparable& r) const {
return *data < *(r.getData());
}
template
bool comparable::operator ==(const comparable& r) const {
return *(this->data) == *(r.getData());
}
template
bool comparable::operator >(const comparable& r) const {
return *data > *(r.getData());
}
template
t* comparable::getData() const {
return data;
}
#endif //_COMPARABLE_H_و
#ifndef _NODE_H_
#define _NODE_H_
#include "comparable.h"
#include
using namespace std;
template
class node{
public:
node(comparable*);
~node();
void setData(comparable*);
comparable* getData();
node* getRight() const;
node* getLeft() const;
void setRight(node*);
void setLeft(node*);
private:
node* right;
node* left;
comparable* data;
};
template
node* node::getRight() const{
return right;
}
template
node* node::getLeft() const{
return left;
}
template
void node::setRight(node* r){
right = r;
}
template
void node::setLeft(node* l){
left = l;
}
template
comparable* node::getData(){
return data;
}
template
node::node(comparable* d){
right = NULL;
left = NULL;
data = d;
}
template
node::~node(){
delete right;
delete left;
delete data;
}
template
void node::setData(comparable* d){
data = d;
}
#endif //_NODE_H_و المطلوب كتابة bst.h لكي يعمل البرنامج و ايضا يجب ان يكون
bst class should inherit and implement the public methods of the container class.