Я не совсем понимаю, что ставить в скобках для типа данных. Я также застрял на том, как заставить эту программу работать. Как будто мне трудно понять концепцию классов. Это то, что я имею до сих пор с программой. Для assignment5.h я запутался в том, что ставить в скобки. Кроме того, если вы можете объяснить мне указатели и узлы, это было бы неплохо. Так запутался!
**assignment5.cpp**
#include "assignment5.h"
#include <vector>
#include<iostream>
#include <iomanip>
using namespace std;
//------------------------------------------------
// Do not modify this section of code
//------------------------------------------------
const int MAX_SIZE = 1000;
const int MAX_COUNT = 20;
const int WIDTH = 5;
const int ROW_SIZE = 5;
int mcount = 0;
int rcount = 0;
void display(int d) {
if (mcount < MAX_COUNT) {
cout << setw(WIDTH) << d;
mcount++;
rcount++;
if (rcount == ROW_SIZE) {
cout << endl;
rcount = 0;
}
}
}
//--------------------------------------------
// End
//---
**assignment5.h**
#ifndef ASSIGNMENT5
#define ASSIGMENT5
// You need to add definition of the Node class
//--------------------------
class binTree {
public:
binTree() : root{ nullptr } {}
virtual void insert(int);
unsigned height() const;
unsigned size() const;
void inorder(void(*)(int));
void preorder(void(*)(int));
void postorder(void(*)(int));
protected:
Node* root;
private:
void insert(Node*& ptr, int root, int data)
{
if (ptr == NULL)
ptr = new Node(data);
else if (val < ptr->data)
insert(ptr->left, data);
else
insert(ptr->right, data);
};
unsigned height(Node* n)
{
if (n == nullptr)
return 0; // the height of an empty tree
else
{
int lh = height(n->left);
int rh = height(n->right); // use the larger one
if (lh > rh)
return(lh + 1);
else return(rh + 1);
}
}
unsigned size(Node*) const;
{
if (node == NULL)
return 0;
else
return(size(node->left) + 1 + size(node->right));
}
void inorder(Node*, void(*)(int))
{
if (p != NULL)
{
inorder(p->left);
cout << p->data;
inorder(p->right);
}
}
void preorder(Node*, void(*)(int))
{
if (p != NULL)
{
cout << p->data;
preorder(p->left);
preorder(p->right);
}
};
void postorder(Node*, void(*)(int));
{
if (p != NULL)
{
postorder(p->left);
postorder(p->right);
cout << p->data;
}
};
};
#endif
**node.h**
#ifndef Node_H
#define Node_H
class binTree;
using namespace std;
class Node
{
friend class binTree;
public:
Node(int nData, Node* nLeft = nullptr, Node* nRight = nullptr) : data(nData), left(nLeft), right(nRight)
{}
int data;
Node* left;
Node* right;
};
#endif