0% found this document useful (0 votes)
3 views

Tree student program

Tree program in c++

Uploaded by

ahmedilyas5440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Tree student program

Tree program in c++

Uploaded by

ahmedilyas5440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <iostream>

Using namespace std;

Struct Node{

Int id;

String Name;

Int marks;

Node *Left;

Node *Right;

};

Class student{

Public:

Node *Root;

Student(){

Root=NULL;

Node *Insert(int d,Node *temp){

If(temp==NULL){

Temp=new Node;

Temp->id=d;

Cout<<”Enter student name”<<endl;

Cin>>temp->Name;

Cout<<”Enter student Marks”<<endl;

Cin>>temp->marks;

Temp->Left=NULL;

Temp->Right=NULL;

If(Root==NULL){

Root=temp;

}
}

Else if(temp->id>d){

Temp->Left=Insert(d,temp->Left);

Else{

Temp->Right=Insert(d,temp->Right);

Return temp;

Void predisplay(Node *temp){

Int f=0;

If(temp!=NULL){

Cout<<”Student id is “<<temp->id<<endl;

Cout<<”Student Name is “<<temp->Name<<endl;

Cout<<”Student Marks are “<<temp->marks<<endl;

Predisplay(temp->Left);

Predisplay(temp->Right);

F=1;

/*if(f==0){

Cout<<”There is not record of student”<<endl;

}*/

Void Search(int d, Node *temp){

If(temp!=NULL){

If(temp->id==d){

Cout<<”Student id is “<<temp->id<<endl;
Cout<<”Student Name is “<<temp->Name<<endl;

Cout<<”Student Marks are “<<temp->marks<<endl;

Else if(temp->id>d){

Search(d,temp->Left);

Else{

Search(d,temp->Right);

Else {

Cout<<”Student with this id is not found”<<endl;

};

Int main() {

Student s1;

Int ch;

While(true){

Cout<<””<<endl;

Cout<<”Menu”<<endl;

Cout<<”1. Insert Student”<<endl;

Cout<<”2. Display Students record”<<endl;

Cout<<”3. Search Student”<<endl;

Cout<<”4. Exit”<<endl;

Cout<<”Enter your choice”<<endl;

Cin>>ch;

Switch(ch){
Case 1:

Int ss;

Cout<<”Enter Student id”<<endl;

Cin>>ss;

S1.Insert(ss,s1.Root);

Break;

Case 2:

S1.predisplay(s1.Root);

Break;

Case 3:

Cout<<”Enter the id of Student to search”<<endl;

Int sea;

Cin>>sea;

S1.Search(sea,s1.Root);

Break;

Case 4:

Return 0;

Break;

Default:

Cout<<”Invalid input…..”<<endl;

Return 0;
}

You might also like