23 Tree C Build a 23 Tree from a set of numbers found in fi

2-3 Tree - C++

Build a 2-3 Tree from a set of numbers found in file RandNbrs.txt. Print out the root and its children and print out the leaves of the tree. Print each node as a pair (3, 6).

Data file:

91
117
84
50
119
74
128
108
112
114
55
95
131
77
111
141
145
92
86
54
52
103
142
132
71
66
68
97
76
121
88
62
149
85
144
53
61
72
83
123
118
94
107
87
109
73
79
140
138
56

Solution

struct TreeNode{

int Sdata,Ldata;

    TreeNode *Parent,*Left,*Mid,*Right;

};

class Two_Three_Tree{

private:

    TreeNode *root;

public:

    Two_Three_Tree()

    {

        TreeNode s;

        s.Sdata=-1;

        s.Ldata=-1;

       root=new TreeNode;

        root=NULL;

        s.Parent=NULL;

        s.Left=NULL;

        s.Mid=NULL;

        s.Right=NULL;

    }

    ~Two_Three_Tree();

    bool IsEmpty()

    {

    if(root==NULL)

        return true;

    return false;

    }

    

    bool is_Two_Node(TreeNode *N)

    {

    if(N->Sdata!=-1 && N->Ldata!=-1 && N->Left==NULL && N->Right==NULL)

        return true;

    return false;

    }

    bool is_three_Node(TreeNode *N)

    {

    if(N->Ldata!=-1 && N->Sdata!=-1 && N->Left==NULL && N->Right==NULL && N->Mid==NULL)

       return true;

    return false;

    }

    TreeNode * Search_leaf(int a)

    {

    TreeNode *temp=root;

    while(temp!=NULL)

    {

       if(a<temp->Sdata)

            temp=temp->Left;

        else if(a<temp->Sdata&&a>temp->Ldata)

            temp=temp->Mid;

       else

            temp=temp->Right;

    }

    return temp;

    }

};

2-3 Tree - C++ Build a 2-3 Tree from a set of numbers found in file RandNbrs.txt. Print out the root and its children and print out the leaves of the tree. Prin
2-3 Tree - C++ Build a 2-3 Tree from a set of numbers found in file RandNbrs.txt. Print out the root and its children and print out the leaves of the tree. Prin
2-3 Tree - C++ Build a 2-3 Tree from a set of numbers found in file RandNbrs.txt. Print out the root and its children and print out the leaves of the tree. Prin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site