I’m working on a project about Data structures.
In the first , I wrote everything in main but it sounds like C . But as I learned, I tried to thinkk OOP and do as little as possible in my main() methods.
I’ve implemented some opertation in my class like add,delet,find.it’s too easy to implement its .
class ARB
{
private:
struct BT
{
int data;
BT *l;
BT *r;
};
struct BT *p;
public
ARB();
~ARB();
void del(int n);
void add(int n);
};
void ARB::del(int num)
{
//The code ,don't care about it
};
main()
{
//
BTR T;
T.add(3);
T.add(5);
};
But I arrived to the big program
How can I define a methode which have to use a binary tree and to get a stack
STACK ARB::MyFunct(BT* p)
{
// The code don't care about it
}
How can I apply it in the main programme
main()
{
//
BT T;
T.add(3);
T.add(5);
STACK S;
BT* p
S=T.MyFunct(p); // error C2664 cannot convert parametre 1
};
**mention :I implement STACK class
There’s a few issues here. For one thing, add() is a member function of ARB, not BT. And, BT is a private subclass of ARB, so it can’t be accessed from main(). p is a private member of ARB (as it should be), but it should really be a direct variable, not a pointer, so it will be automatically created and destroyed with ARB. As is, p is never initialized and there’s no way to do so from outside ARB.
I’m guessing here that ARB uses its internal BT p for internal storage, so the implementations of add() and del() both operate on p, and that MyFunct() is supposed to take that BT and generate a stack from it. If so, MyFunct() should take no parameters and simply reference p directly.
So main() would look something like:
This is all assuming I’ve correctly deduced your intentions here.