Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node
- {
- int data;
- Node* left;
- Node* right;
- };
- using namespace std;
- class Tree
- {
- private:
- Node *head =new Node;
- Node *rood;
- int n = 0;
- public:
- void add()
- {
- cout<<"введите корень(0)"<<endl;
- cin>>(head->data);
- head->left = NULL;
- head->right = NULL;
- cout<<"вводите вершины('0' означает NULL)"<<endl;
- add(head);
- }
- void add(Node *uz)
- {
- int gl,gr;
- Node* tmpl = new Node;
- cin>>gl;
- if ((gl)!=0)
- {
- tmpl->data = gl;
- tmpl->left = NULL;
- tmpl->right = NULL;
- uz->left = tmpl;
- n++;
- add(tmpl);
- }
- else{
- tmpl = NULL;
- uz->left = tmpl;
- }
- Node* tmpr = new Node;
- cin>>gr;
- if (gr!=0)
- {
- tmpr->data = gr;
- tmpr->left = NULL;
- tmpr->right = NULL;
- uz->right = tmpr;
- add(tmpr);
- }
- else{
- tmpr= NULL;
- uz->right = tmpr;
- }
- }
- void print()
- {
- print(head,5);
- }
- void print(Node *p,int level)
- {
- if(p)
- {
- print(p->right,level + 1);
- for(int i = 0;i< level;i++) cout<<" ";
- cout << p->data << endl;
- print(p->left,level + 1);
- }
- }
- };
- int main()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement