Group A Aassign 1 Book
Group A Aassign 1 Book
Problem Statement: A book consists of chapters, chapters consist of sections and sections consist
of subsections. Construct a tree and print the nodes. Find the time and space requirements of your
method.
#include<iostream>
#include<string.h>
class BTNode
public:
char data[10];
};
class Book
char d[20];
Book()
void create()
char ans='y';
do
cin>>temp->data;
temp->left=NULL;
temp->right=NULL;
if(root == NULL)
root = temp;
else
insert(root, temp);
cin>>ans;
char ch;
cin>>ch;
if(root->right == NULL)
root->right = temp;
else
insert(root->right, temp);
else
if(root->left == NULL)
root->left = temp;
else
insert(root->left, temp);
if(root!=NULL)
rec_inorder(root->left);
cout<<root->data;
rec_inorder(root->right);
int h = height(root);
int i;
for(i=1;i<=h;i++)
{
cout<<"\n";
printLevel(root,i);
if(root == NULL)
return;
if(level == 1 )
//
cout<<" "<<root->data;
else if (level>1)
printLevel(root->left,level-1);
printLevel(root->right,level-1);
if(node == NULL)
return 0;
else
return (lheight+1);
else
return (rheight+1);
};
int main()
int choice;
Book b1;
do
cout<"\n\tMain Menu:";
cout<<"\n1.Create";
cout<<"\n2.Display";
cout<<"\n3.Exit";
cin>>choice;
switch(choice)
case 1: b1.create();break;
case 2: if(b1.root==NULL)
else
b1.printLevelOrder(b1.root);
break;
}while(choice <=2);
return 0; }