

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This task was assigned by Prof. Chandrashekar Baag at Amrita Vishwa Vidyapeetham. This assignment is related to Data Structures and Representation course. It includes: Tree, Structure, Root, While, Loop, Choice, Sum, Mean, Input, Output, Display
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


#include<iostream.h> #include<conio.h> #include<stdlib.h>
struct tree { int data; struct tree *right; struct tree *left; } root=NULL,curr;
void ins(struct tree *,struct tree); void min(struct tree *); void max(struct tree *); void main() { int choice; char y;
while (1) { clrscr(); cout<<"\n1........Insert\n2.........Min\n3.......Find Max\n4........Exit"; cin>>choice; switch (choice) { case 1: { cout<<"\nEnter the data"; curr=new tree; cin>>curr->data; curr->right=NULL; curr->left=NULL; ins(&root,curr); break; } case 2: min(root); break; } case 3: { max(root); break; } case 4: { exit(4);
break; } getch();
void ins(tree root,p)
{ if (root==NULL) root=p; else { if (root->data==p->data) cout<<"cannot insert"; else { if(root->data=p->data) ins(&(root)->right,p); else ins(&(root)->left,p);
}
void min(struct tree *curr) { while(curr->left!=NULL) { curr=curr->left; } cout<<"the min valve is"<<current->data; }
void max(struct tree *curr) { { while(curr->right!=NULL) { curr=curr->right; } cout<<"the min valve is"<<curr->data; }
}