Trees Structure 2-Data Structures and Representation-Assigment, Exercises of Data Structures and Algorithms

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

2011/2012

Uploaded on 07/30/2012

dhanvantari
dhanvantari 🇮🇳

2

(2)

45 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#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();
docsity.com
pf2

Partial preview of the text

Download Trees Structure 2-Data Structures and Representation-Assigment and more Exercises Data Structures and Algorithms in PDF only on Docsity!

#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();

docsity.com

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; }

}

docsity.com