SlideShare a Scribd company logo
1 of 3
Download to read offline
The following is to be written in Java:
The following is the BSTree.java I have written. Use this code and extend it to achieve the
problems listed above:
import java.io.*;
import java.util.*;
class BSTNode {
BSTNode left, right;
Comparable data;
public BSTNode(){
left = null;
right = null;
data = 0;
}
/* Constructor */
public BSTNode(Comparable n){
left = null;
right = null;
data = n;
}
public void setLeft(BSTNode n){
left = n;
}
public void setRight(BSTNode n){
right = n;
}
public BSTNode getLeft(){
return left;
}
public BSTNode getRight(){
return right;
}
public void setData(int d){
data = d;
}
public Comparable getData(){
return data;
}
}
class BST {
private BSTNode root;
/* Constructor */
public BST(){
root = null;
}
/* Functions to insert data */
public void insert(Comparable data){
if (root == null){
root = new BSTNode(data);
}
else insert(root, data);
}
/* Function to insert data recursively */
private void insert(BSTNode node, Comparable data){
//if (node.getData().equals(data)) thr();
if (data.compareTo(node.getData()) < 0){
//when data < node's data
//add data as left child of node if it doesnt have one
//else insert into node's left subtree
if (node.getLeft() == null) node.setLeft(new BSTNode(data));
else insert(node.getLeft(), data);
} else {
//when data > node's data
//insert data as right child of node if it doesnt have one
//else insert into node's right subtree
if (node.getRight() == null) node.setRight(new BSTNode(data));
else insert(node.getRight(), data);
}
}
public boolean search(Comparable data) {
return search(root, data);
}
private static boolean search(BSTNode node, Comparable data) {
if (node == null) return false;
if (node.getData().equals(data)) return true;
if (data.compareTo(node.getData()) < 0) {
// data < this node's key; look in left subtree
return search(node.getLeft(), data);
}
else {
// data > this node's key; look in right subtree
return search(node.getRight(), data);
}
}
/* Function for inorder traversal */
public void inorder(){
inorder(root);
}
private void inorder(BSTNode r){
if (r != null){
inorder(r.getLeft());
System.out.print(r.getData() +" ");
inorder(r.getRight());
}
}
}
public class BSTree {
public static void main(String[] args) {
BST bst = new BST();
int[] x = {4,2,6,1,3,5,7,8,12,15,10,13,14,9};
for(int i=0;i
Solution
REDBLACK.java
/*
--------------------------------------------------------------------------------------------------------------------
-----------------------------------------------
RBBST.java

More Related Content

Similar to The following is to be written in JavaThe following is the BSTree.pdf

Question In C Programming In mathematics, a set is a colle...Sav.pdf
Question In C Programming In mathematics, a set is a colle...Sav.pdfQuestion In C Programming In mathematics, a set is a colle...Sav.pdf
Question In C Programming In mathematics, a set is a colle...Sav.pdfarihantcomp1008
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfarchanaemporium
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3ecomputernotes
 
For this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxFor this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxbudbarber38650
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfferoz544
 
How to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdfHow to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdffeelingcomputors
 
This code currently works. Run it and get a screen shot of its ou.docx
 This code currently works. Run it and get a screen shot of its ou.docx This code currently works. Run it and get a screen shot of its ou.docx
This code currently works. Run it and get a screen shot of its ou.docxKomlin1
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdframbagra74
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfmanjan6
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdfasarudheen07
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdfdatabase propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdffashiionbeutycare
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdffonecomp
 
This code currently works... Run it and get a screen shot of its .docx
 This code currently works... Run it and get a screen shot of its .docx This code currently works... Run it and get a screen shot of its .docx
This code currently works... Run it and get a screen shot of its .docxKomlin1
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdfadityastores21
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfsiennatimbok52331
 
Write a function in C++ to generate an N-node random binary search t.pdf
Write a function in C++ to generate an N-node random binary search t.pdfWrite a function in C++ to generate an N-node random binary search t.pdf
Write a function in C++ to generate an N-node random binary search t.pdfinfo824691
 

Similar to The following is to be written in JavaThe following is the BSTree.pdf (20)

Question In C Programming In mathematics, a set is a colle...Sav.pdf
Question In C Programming In mathematics, a set is a colle...Sav.pdfQuestion In C Programming In mathematics, a set is a colle...Sav.pdf
Question In C Programming In mathematics, a set is a colle...Sav.pdf
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
 
For this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxFor this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docx
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
 
How to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdfHow to do the main method for this programBinaryNode.javapublic.pdf
How to do the main method for this programBinaryNode.javapublic.pdf
 
This code currently works. Run it and get a screen shot of its ou.docx
 This code currently works. Run it and get a screen shot of its ou.docx This code currently works. Run it and get a screen shot of its ou.docx
This code currently works. Run it and get a screen shot of its ou.docx
 
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
5. Design and implement a method contains 2 for BinarySearchTree, fu.pdf
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
Help in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdfHelp in JAVAThis program should input numerator and denominator f.pdf
Help in JAVAThis program should input numerator and denominator f.pdf
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
COW
COWCOW
COW
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdfdatabase propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
This code currently works... Run it and get a screen shot of its .docx
 This code currently works... Run it and get a screen shot of its .docx This code currently works... Run it and get a screen shot of its .docx
This code currently works... Run it and get a screen shot of its .docx
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Write a function in C++ to generate an N-node random binary search t.pdf
Write a function in C++ to generate an N-node random binary search t.pdfWrite a function in C++ to generate an N-node random binary search t.pdf
Write a function in C++ to generate an N-node random binary search t.pdf
 

More from eyewatchsystems

In 9. 3-1 BALANCE SHEET The assets of Dallas & Associates consist e.pdf
In 9. 3-1 BALANCE SHEET The assets of Dallas & Associates consist e.pdfIn 9. 3-1 BALANCE SHEET The assets of Dallas & Associates consist e.pdf
In 9. 3-1 BALANCE SHEET The assets of Dallas & Associates consist e.pdfeyewatchsystems
 
I need help understanding the Pan Tompkins algorythm, and Id also .pdf
I need help understanding the Pan Tompkins algorythm, and Id also .pdfI need help understanding the Pan Tompkins algorythm, and Id also .pdf
I need help understanding the Pan Tompkins algorythm, and Id also .pdfeyewatchsystems
 
I believe my chosen answer is correct, but Im not entirely positiv.pdf
I believe my chosen answer is correct, but Im not entirely positiv.pdfI believe my chosen answer is correct, but Im not entirely positiv.pdf
I believe my chosen answer is correct, but Im not entirely positiv.pdfeyewatchsystems
 
how does genies transcript illustrate the statement we learn to .pdf
how does genies transcript illustrate the statement we learn to .pdfhow does genies transcript illustrate the statement we learn to .pdf
how does genies transcript illustrate the statement we learn to .pdfeyewatchsystems
 
How many different alleles can a gene have Explain.SolutionEa.pdf
How many different alleles can a gene have Explain.SolutionEa.pdfHow many different alleles can a gene have Explain.SolutionEa.pdf
How many different alleles can a gene have Explain.SolutionEa.pdfeyewatchsystems
 
Comment on the behavior of the different types of flexures (crab-leg.pdf
Comment on the behavior of the different types of flexures (crab-leg.pdfComment on the behavior of the different types of flexures (crab-leg.pdf
Comment on the behavior of the different types of flexures (crab-leg.pdfeyewatchsystems
 
human color-blindness mutations result from A.reciprocal translocat.pdf
human color-blindness mutations result from A.reciprocal translocat.pdfhuman color-blindness mutations result from A.reciprocal translocat.pdf
human color-blindness mutations result from A.reciprocal translocat.pdfeyewatchsystems
 
Generation 1 2 3 4 6 5 6 7 SolutionThe chances of their first c.pdf
Generation 1 2 3 4 6 5 6 7 SolutionThe chances of their first c.pdfGeneration 1 2 3 4 6 5 6 7 SolutionThe chances of their first c.pdf
Generation 1 2 3 4 6 5 6 7 SolutionThe chances of their first c.pdfeyewatchsystems
 
Explain how cell division occurs in the germ (meiosis) cells of anim.pdf
Explain how cell division occurs in the germ (meiosis) cells of anim.pdfExplain how cell division occurs in the germ (meiosis) cells of anim.pdf
Explain how cell division occurs in the germ (meiosis) cells of anim.pdfeyewatchsystems
 
Ecologists are sampling mice from different parks in New York City. M.pdf
Ecologists are sampling mice from different parks in New York City. M.pdfEcologists are sampling mice from different parks in New York City. M.pdf
Ecologists are sampling mice from different parks in New York City. M.pdfeyewatchsystems
 
Describe the electronic configuration of a given element. Why are we.pdf
Describe the electronic configuration of a given element. Why are we.pdfDescribe the electronic configuration of a given element. Why are we.pdf
Describe the electronic configuration of a given element. Why are we.pdfeyewatchsystems
 
Assets are listed on the balance sheet in order ofincreasing size .pdf
Assets are listed on the balance sheet in order ofincreasing size .pdfAssets are listed on the balance sheet in order ofincreasing size .pdf
Assets are listed on the balance sheet in order ofincreasing size .pdfeyewatchsystems
 
1) Even the simplest types of infectious agents must have DNA, RNA, .pdf
1) Even the simplest types of infectious agents must have DNA, RNA, .pdf1) Even the simplest types of infectious agents must have DNA, RNA, .pdf
1) Even the simplest types of infectious agents must have DNA, RNA, .pdfeyewatchsystems
 
1-A) What types of data document patterns and processes of evoluti.pdf
1-A) What types of data document patterns and processes of evoluti.pdf1-A) What types of data document patterns and processes of evoluti.pdf
1-A) What types of data document patterns and processes of evoluti.pdfeyewatchsystems
 
Which of the following does not take place in a signaltransduction pa.pdf
Which of the following does not take place in a signaltransduction pa.pdfWhich of the following does not take place in a signaltransduction pa.pdf
Which of the following does not take place in a signaltransduction pa.pdfeyewatchsystems
 
Which term indicates the evolution of many closely related species fr.pdf
Which term indicates the evolution of many closely related species fr.pdfWhich term indicates the evolution of many closely related species fr.pdf
Which term indicates the evolution of many closely related species fr.pdfeyewatchsystems
 
you inoculate an LB tube with an aerobic bacterium and incubate it f.pdf
you inoculate an LB tube with an aerobic bacterium and incubate it f.pdfyou inoculate an LB tube with an aerobic bacterium and incubate it f.pdf
you inoculate an LB tube with an aerobic bacterium and incubate it f.pdfeyewatchsystems
 
What is meant by the relationship or the two strands of DNA The rig.pdf
What is meant by the relationship or the two strands of DNA  The rig.pdfWhat is meant by the relationship or the two strands of DNA  The rig.pdf
What is meant by the relationship or the two strands of DNA The rig.pdfeyewatchsystems
 
Which of the following categories of control can include the logical.pdf
Which of the following categories of control can include the logical.pdfWhich of the following categories of control can include the logical.pdf
Which of the following categories of control can include the logical.pdfeyewatchsystems
 
What is it, and how does Chromatic Dispersion Compensation work.pdf
What is it, and how does Chromatic Dispersion Compensation work.pdfWhat is it, and how does Chromatic Dispersion Compensation work.pdf
What is it, and how does Chromatic Dispersion Compensation work.pdfeyewatchsystems
 

More from eyewatchsystems (20)

In 9. 3-1 BALANCE SHEET The assets of Dallas & Associates consist e.pdf
In 9. 3-1 BALANCE SHEET The assets of Dallas & Associates consist e.pdfIn 9. 3-1 BALANCE SHEET The assets of Dallas & Associates consist e.pdf
In 9. 3-1 BALANCE SHEET The assets of Dallas & Associates consist e.pdf
 
I need help understanding the Pan Tompkins algorythm, and Id also .pdf
I need help understanding the Pan Tompkins algorythm, and Id also .pdfI need help understanding the Pan Tompkins algorythm, and Id also .pdf
I need help understanding the Pan Tompkins algorythm, and Id also .pdf
 
I believe my chosen answer is correct, but Im not entirely positiv.pdf
I believe my chosen answer is correct, but Im not entirely positiv.pdfI believe my chosen answer is correct, but Im not entirely positiv.pdf
I believe my chosen answer is correct, but Im not entirely positiv.pdf
 
how does genies transcript illustrate the statement we learn to .pdf
how does genies transcript illustrate the statement we learn to .pdfhow does genies transcript illustrate the statement we learn to .pdf
how does genies transcript illustrate the statement we learn to .pdf
 
How many different alleles can a gene have Explain.SolutionEa.pdf
How many different alleles can a gene have Explain.SolutionEa.pdfHow many different alleles can a gene have Explain.SolutionEa.pdf
How many different alleles can a gene have Explain.SolutionEa.pdf
 
Comment on the behavior of the different types of flexures (crab-leg.pdf
Comment on the behavior of the different types of flexures (crab-leg.pdfComment on the behavior of the different types of flexures (crab-leg.pdf
Comment on the behavior of the different types of flexures (crab-leg.pdf
 
human color-blindness mutations result from A.reciprocal translocat.pdf
human color-blindness mutations result from A.reciprocal translocat.pdfhuman color-blindness mutations result from A.reciprocal translocat.pdf
human color-blindness mutations result from A.reciprocal translocat.pdf
 
Generation 1 2 3 4 6 5 6 7 SolutionThe chances of their first c.pdf
Generation 1 2 3 4 6 5 6 7 SolutionThe chances of their first c.pdfGeneration 1 2 3 4 6 5 6 7 SolutionThe chances of their first c.pdf
Generation 1 2 3 4 6 5 6 7 SolutionThe chances of their first c.pdf
 
Explain how cell division occurs in the germ (meiosis) cells of anim.pdf
Explain how cell division occurs in the germ (meiosis) cells of anim.pdfExplain how cell division occurs in the germ (meiosis) cells of anim.pdf
Explain how cell division occurs in the germ (meiosis) cells of anim.pdf
 
Ecologists are sampling mice from different parks in New York City. M.pdf
Ecologists are sampling mice from different parks in New York City. M.pdfEcologists are sampling mice from different parks in New York City. M.pdf
Ecologists are sampling mice from different parks in New York City. M.pdf
 
Describe the electronic configuration of a given element. Why are we.pdf
Describe the electronic configuration of a given element. Why are we.pdfDescribe the electronic configuration of a given element. Why are we.pdf
Describe the electronic configuration of a given element. Why are we.pdf
 
Assets are listed on the balance sheet in order ofincreasing size .pdf
Assets are listed on the balance sheet in order ofincreasing size .pdfAssets are listed on the balance sheet in order ofincreasing size .pdf
Assets are listed on the balance sheet in order ofincreasing size .pdf
 
1) Even the simplest types of infectious agents must have DNA, RNA, .pdf
1) Even the simplest types of infectious agents must have DNA, RNA, .pdf1) Even the simplest types of infectious agents must have DNA, RNA, .pdf
1) Even the simplest types of infectious agents must have DNA, RNA, .pdf
 
1-A) What types of data document patterns and processes of evoluti.pdf
1-A) What types of data document patterns and processes of evoluti.pdf1-A) What types of data document patterns and processes of evoluti.pdf
1-A) What types of data document patterns and processes of evoluti.pdf
 
Which of the following does not take place in a signaltransduction pa.pdf
Which of the following does not take place in a signaltransduction pa.pdfWhich of the following does not take place in a signaltransduction pa.pdf
Which of the following does not take place in a signaltransduction pa.pdf
 
Which term indicates the evolution of many closely related species fr.pdf
Which term indicates the evolution of many closely related species fr.pdfWhich term indicates the evolution of many closely related species fr.pdf
Which term indicates the evolution of many closely related species fr.pdf
 
you inoculate an LB tube with an aerobic bacterium and incubate it f.pdf
you inoculate an LB tube with an aerobic bacterium and incubate it f.pdfyou inoculate an LB tube with an aerobic bacterium and incubate it f.pdf
you inoculate an LB tube with an aerobic bacterium and incubate it f.pdf
 
What is meant by the relationship or the two strands of DNA The rig.pdf
What is meant by the relationship or the two strands of DNA  The rig.pdfWhat is meant by the relationship or the two strands of DNA  The rig.pdf
What is meant by the relationship or the two strands of DNA The rig.pdf
 
Which of the following categories of control can include the logical.pdf
Which of the following categories of control can include the logical.pdfWhich of the following categories of control can include the logical.pdf
Which of the following categories of control can include the logical.pdf
 
What is it, and how does Chromatic Dispersion Compensation work.pdf
What is it, and how does Chromatic Dispersion Compensation work.pdfWhat is it, and how does Chromatic Dispersion Compensation work.pdf
What is it, and how does Chromatic Dispersion Compensation work.pdf
 

Recently uploaded

internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 

Recently uploaded (20)

internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 

The following is to be written in JavaThe following is the BSTree.pdf

  • 1. The following is to be written in Java: The following is the BSTree.java I have written. Use this code and extend it to achieve the problems listed above: import java.io.*; import java.util.*; class BSTNode { BSTNode left, right; Comparable data; public BSTNode(){ left = null; right = null; data = 0; } /* Constructor */ public BSTNode(Comparable n){ left = null; right = null; data = n; } public void setLeft(BSTNode n){ left = n; } public void setRight(BSTNode n){ right = n; } public BSTNode getLeft(){ return left; } public BSTNode getRight(){ return right; } public void setData(int d){ data = d; } public Comparable getData(){
  • 2. return data; } } class BST { private BSTNode root; /* Constructor */ public BST(){ root = null; } /* Functions to insert data */ public void insert(Comparable data){ if (root == null){ root = new BSTNode(data); } else insert(root, data); } /* Function to insert data recursively */ private void insert(BSTNode node, Comparable data){ //if (node.getData().equals(data)) thr(); if (data.compareTo(node.getData()) < 0){ //when data < node's data //add data as left child of node if it doesnt have one //else insert into node's left subtree if (node.getLeft() == null) node.setLeft(new BSTNode(data)); else insert(node.getLeft(), data); } else { //when data > node's data //insert data as right child of node if it doesnt have one //else insert into node's right subtree if (node.getRight() == null) node.setRight(new BSTNode(data)); else insert(node.getRight(), data); } } public boolean search(Comparable data) { return search(root, data); }
  • 3. private static boolean search(BSTNode node, Comparable data) { if (node == null) return false; if (node.getData().equals(data)) return true; if (data.compareTo(node.getData()) < 0) { // data < this node's key; look in left subtree return search(node.getLeft(), data); } else { // data > this node's key; look in right subtree return search(node.getRight(), data); } } /* Function for inorder traversal */ public void inorder(){ inorder(root); } private void inorder(BSTNode r){ if (r != null){ inorder(r.getLeft()); System.out.print(r.getData() +" "); inorder(r.getRight()); } } } public class BSTree { public static void main(String[] args) { BST bst = new BST(); int[] x = {4,2,6,1,3,5,7,8,12,15,10,13,14,9}; for(int i=0;i Solution REDBLACK.java /* -------------------------------------------------------------------------------------------------------------------- ----------------------------------------------- RBBST.java