SlideShare a Scribd company logo
1 of 14
Download to read offline
import java.util.Scanner;
class BinaryNode
{
BinaryNode left, right;
int data;
public BinaryNode()
{
left = null;
right = null;
data = 0;
}
public BinaryNode(int n)
{
left = null;
right = null;
data = n;
}
public void setLeft(BinaryNode n)
{
left = n;
}
public void setRight(BinaryNode n)
{
right = n;
}
public BinaryNode getLeft()
{
return left;
}
public BinaryNode getRight()
{
return right;
}
public void setData(int d)
{
data = d;
}
public int getData()
{
return data;
}
}
class Binary
{
private BinaryNode root;
public Binary()
{
root = null;
}
public boolean isEmpty()
{
return root == null;
}
public void insert(int data)
{
root = insert(root, data);
}
private BinaryNode insert(BinaryNode node, int data)
{
if (node == null)
node = new BinaryNode(data);
else
{
if (data <= node.getData())
node.left = insert(node.left, data);
else
node.right = insert(node.right, data);
}
return node;
}
public void delete(int k)
{
if (isEmpty())
System.out.println("Tree Empty");
else if (search(k) == false)
System.out.println("Sorry "+ k +" is not present");
else
{
root = delete(root, k);
System.out.println(k+ " deleted from the tree");
}
}
private BinaryNode delete(BinaryNode root, int k)
{
BinaryNode p, p2, n;
if (root.getData() == k)
{
BinaryNode lt, rt;
lt = root.getLeft();
rt = root.getRight();
if (lt == null && rt == null)
return null;
else if (lt == null)
{
p = rt;
return p;
}
else if (rt == null)
{
p = lt;
return p;
}
else
{
p2 = rt;
p = rt;
while (p.getLeft() != null)
p = p.getLeft();
p.setLeft(lt);
return p2;
}
}
if (k < root.getData())
{
n = delete(root.getLeft(), k);
root.setLeft(n);
}
else
{
n = delete(root.getRight(), k);
root.setRight(n);
}
return root;
}
public boolean search(int val)
{
return search(root, val);
}
private boolean search(BinaryNode r, int val)
{
boolean found = false;
while ((r != null) && !found)
{
int rval = r.getData();
if (val < rval)
r = r.getLeft();
else if (val > rval)
r = r.getRight();
else
{
found = true;
break;
}
found = search(r, val);
}
return found;
}
public void inorder()
{
inorder(root);
}
private void inorder(BinaryNode r)
{
if (r != null)
{
inorder(r.getLeft());
System.out.print(r.getData() +" ");
inorder(r.getRight());
}
}
public void preorder()
{
preorder(root);
}
private void preorder(BinaryNode r)
{
if (r != null)
{
System.out.print(r.getData() +" ");
preorder(r.getLeft());
preorder(r.getRight());
}
}
public void postorder()
{
postorder(root);
}
private void postorder(BinaryNode r)
{
if (r != null)
{
postorder(r.getLeft());
postorder(r.getRight());
System.out.print(r.getData() +" ");
}
}
}
public class BinarySearchTree
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Binary Binary = new Binary();
System.out.println("Binary Search Tree Test ");
char ch;
do
{
System.out.println(" Binary Search Tree Operations ");
System.out.println("1. insert ");
System.out.println("2. delete");
System.out.println("3. search");
System.out.println("4. check empty");
int choice = scan.nextInt();
switch (choice)
{
case 1 :
System.out.println("Enter integer element to insert");
Binary.insert( scan.nextInt() );
break;
case 2 :
System.out.println("Enter integer element to delete");
Binary.delete( scan.nextInt() );
break;
case 3 :
System.out.println("Enter integer element to search");
System.out.println("Search result : "+ Binary.search( scan.nextInt() ));
break;
case 4 :
System.out.println("Empty status = "+ Binary.isEmpty());
break;
default :
System.out.println("Wrong Entry  ");
break;
}
System.out.print(" Post order : ");
Binary.postorder();
System.out.print(" Pre order : ");
Binary.preorder();
System.out.print(" In order : ");
Binary.inorder();
System.out.println(" Do you want to continue (Type y or n)  ");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}
}
Solution
import java.util.Scanner;
class BinaryNode
{
BinaryNode left, right;
int data;
public BinaryNode()
{
left = null;
right = null;
data = 0;
}
public BinaryNode(int n)
{
left = null;
right = null;
data = n;
}
public void setLeft(BinaryNode n)
{
left = n;
}
public void setRight(BinaryNode n)
{
right = n;
}
public BinaryNode getLeft()
{
return left;
}
public BinaryNode getRight()
{
return right;
}
public void setData(int d)
{
data = d;
}
public int getData()
{
return data;
}
}
class Binary
{
private BinaryNode root;
public Binary()
{
root = null;
}
public boolean isEmpty()
{
return root == null;
}
public void insert(int data)
{
root = insert(root, data);
}
private BinaryNode insert(BinaryNode node, int data)
{
if (node == null)
node = new BinaryNode(data);
else
{
if (data <= node.getData())
node.left = insert(node.left, data);
else
node.right = insert(node.right, data);
}
return node;
}
public void delete(int k)
{
if (isEmpty())
System.out.println("Tree Empty");
else if (search(k) == false)
System.out.println("Sorry "+ k +" is not present");
else
{
root = delete(root, k);
System.out.println(k+ " deleted from the tree");
}
}
private BinaryNode delete(BinaryNode root, int k)
{
BinaryNode p, p2, n;
if (root.getData() == k)
{
BinaryNode lt, rt;
lt = root.getLeft();
rt = root.getRight();
if (lt == null && rt == null)
return null;
else if (lt == null)
{
p = rt;
return p;
}
else if (rt == null)
{
p = lt;
return p;
}
else
{
p2 = rt;
p = rt;
while (p.getLeft() != null)
p = p.getLeft();
p.setLeft(lt);
return p2;
}
}
if (k < root.getData())
{
n = delete(root.getLeft(), k);
root.setLeft(n);
}
else
{
n = delete(root.getRight(), k);
root.setRight(n);
}
return root;
}
public boolean search(int val)
{
return search(root, val);
}
private boolean search(BinaryNode r, int val)
{
boolean found = false;
while ((r != null) && !found)
{
int rval = r.getData();
if (val < rval)
r = r.getLeft();
else if (val > rval)
r = r.getRight();
else
{
found = true;
break;
}
found = search(r, val);
}
return found;
}
public void inorder()
{
inorder(root);
}
private void inorder(BinaryNode r)
{
if (r != null)
{
inorder(r.getLeft());
System.out.print(r.getData() +" ");
inorder(r.getRight());
}
}
public void preorder()
{
preorder(root);
}
private void preorder(BinaryNode r)
{
if (r != null)
{
System.out.print(r.getData() +" ");
preorder(r.getLeft());
preorder(r.getRight());
}
}
public void postorder()
{
postorder(root);
}
private void postorder(BinaryNode r)
{
if (r != null)
{
postorder(r.getLeft());
postorder(r.getRight());
System.out.print(r.getData() +" ");
}
}
}
public class BinarySearchTree
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Binary Binary = new Binary();
System.out.println("Binary Search Tree Test ");
char ch;
do
{
System.out.println(" Binary Search Tree Operations ");
System.out.println("1. insert ");
System.out.println("2. delete");
System.out.println("3. search");
System.out.println("4. check empty");
int choice = scan.nextInt();
switch (choice)
{
case 1 :
System.out.println("Enter integer element to insert");
Binary.insert( scan.nextInt() );
break;
case 2 :
System.out.println("Enter integer element to delete");
Binary.delete( scan.nextInt() );
break;
case 3 :
System.out.println("Enter integer element to search");
System.out.println("Search result : "+ Binary.search( scan.nextInt() ));
break;
case 4 :
System.out.println("Empty status = "+ Binary.isEmpty());
break;
default :
System.out.println("Wrong Entry  ");
break;
}
System.out.print(" Post order : ");
Binary.postorder();
System.out.print(" Pre order : ");
Binary.preorder();
System.out.print(" In order : ");
Binary.inorder();
System.out.println(" Do you want to continue (Type y or n)  ");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}
}

More Related Content

Similar to import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf

6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. StreamsDEVTYPE
 
import javautilQueue import javautilLinkedList import .pdf
import javautilQueue import javautilLinkedList import .pdfimport javautilQueue import javautilLinkedList import .pdf
import javautilQueue import javautilLinkedList import .pdfADITIEYEWEAR
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfadityaenterprise32
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfshyamsunder1211
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfarjuncorner565
 
usingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfusingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfinfo335653
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 
( PLEASE SHOW HOW TO IMPLEMENT THE DELETION FUNCTION )SAMPLE OUTPU.pdf
( PLEASE SHOW HOW TO IMPLEMENT THE DELETION FUNCTION )SAMPLE OUTPU.pdf( PLEASE SHOW HOW TO IMPLEMENT THE DELETION FUNCTION )SAMPLE OUTPU.pdf
( PLEASE SHOW HOW TO IMPLEMENT THE DELETION FUNCTION )SAMPLE OUTPU.pdfaristogifts99
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfakaluza07
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdffathimafancyjeweller
 
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
 
I need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfI need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfallurafashions98
 
A perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfA perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfmichardsonkhaicarr37
 
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
package edu-ser222-m03_02-   ---  - A binary search tree based impleme.docxpackage edu-ser222-m03_02-   ---  - A binary search tree based impleme.docx
package edu-ser222-m03_02- --- - A binary search tree based impleme.docxfarrahkur54
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfAnkitchhabra28
 
public class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfpublic class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfannaipowerelectronic
 

Similar to import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf (20)

6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
import javautilQueue import javautilLinkedList import .pdf
import javautilQueue import javautilLinkedList import .pdfimport javautilQueue import javautilLinkedList import .pdf
import javautilQueue import javautilLinkedList import .pdf
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
ISCP internal.pdf
ISCP internal.pdfISCP internal.pdf
ISCP internal.pdf
 
week-16x
week-16xweek-16x
week-16x
 
usingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdfusingpackage util;import java.util.;This class implements.pdf
usingpackage util;import java.util.;This class implements.pdf
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
( PLEASE SHOW HOW TO IMPLEMENT THE DELETION FUNCTION )SAMPLE OUTPU.pdf
( PLEASE SHOW HOW TO IMPLEMENT THE DELETION FUNCTION )SAMPLE OUTPU.pdf( PLEASE SHOW HOW TO IMPLEMENT THE DELETION FUNCTION )SAMPLE OUTPU.pdf
( PLEASE SHOW HOW TO IMPLEMENT THE DELETION FUNCTION )SAMPLE OUTPU.pdf
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
This is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdfThis is to test a balanced tree. I need help testing an unbalanced t.pdf
This is to test a balanced tree. I need help testing an unbalanced t.pdf
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.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
 
I need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfI need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdf
 
A perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdfA perfect left-sided binary tree is a binary tree where every intern.pdf
A perfect left-sided binary tree is a binary tree where every intern.pdf
 
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
package edu-ser222-m03_02-   ---  - A binary search tree based impleme.docxpackage edu-ser222-m03_02-   ---  - A binary search tree based impleme.docx
package edu-ser222-m03_02- --- - A binary search tree based impleme.docx
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
public class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdfpublic class Deque {private class Node {public int data;public.pdf
public class Deque {private class Node {public int data;public.pdf
 

More from shaktisinhgandhinaga

3. Data Link Layer is the answer.This is because, SAPs act as an i.pdf
3. Data Link Layer is the answer.This is because, SAPs act as an i.pdf3. Data Link Layer is the answer.This is because, SAPs act as an i.pdf
3. Data Link Layer is the answer.This is because, SAPs act as an i.pdfshaktisinhgandhinaga
 
1. According to most surveys and reports the most infectious disease.pdf
1. According to most surveys and reports the most infectious disease.pdf1. According to most surveys and reports the most infectious disease.pdf
1. According to most surveys and reports the most infectious disease.pdfshaktisinhgandhinaga
 
1) D. Platelets are the blood cells which aid in blood clotting.2).pdf
1) D. Platelets are the blood cells which aid in blood clotting.2).pdf1) D. Platelets are the blood cells which aid in blood clotting.2).pdf
1) D. Platelets are the blood cells which aid in blood clotting.2).pdfshaktisinhgandhinaga
 
Vertical take-off and landing (VTOL) aircraft uses powered rotors fo.pdf
  Vertical take-off and landing (VTOL) aircraft uses powered rotors fo.pdf  Vertical take-off and landing (VTOL) aircraft uses powered rotors fo.pdf
Vertical take-off and landing (VTOL) aircraft uses powered rotors fo.pdfshaktisinhgandhinaga
 
The degree of ionization is influenced by the con.pdf
                     The degree of ionization is influenced by the con.pdf                     The degree of ionization is influenced by the con.pdf
The degree of ionization is influenced by the con.pdfshaktisinhgandhinaga
 
Problem 1 H2SO4 is diprotic, so it gives [H+] o.pdf
                     Problem 1  H2SO4 is diprotic, so it gives [H+] o.pdf                     Problem 1  H2SO4 is diprotic, so it gives [H+] o.pdf
Problem 1 H2SO4 is diprotic, so it gives [H+] o.pdfshaktisinhgandhinaga
 
only one because it exist only one isomer .pdf
                     only one because it exist only one isomer        .pdf                     only one because it exist only one isomer        .pdf
only one because it exist only one isomer .pdfshaktisinhgandhinaga
 
when 71.1 moles of carbon dioxide gas react with .pdf
                     when 71.1 moles of carbon dioxide gas react with .pdf                     when 71.1 moles of carbon dioxide gas react with .pdf
when 71.1 moles of carbon dioxide gas react with .pdfshaktisinhgandhinaga
 
rate at t=0 is R=0.042 Overall order of reaction=.pdf
                     rate at t=0 is R=0.042 Overall order of reaction=.pdf                     rate at t=0 is R=0.042 Overall order of reaction=.pdf
rate at t=0 is R=0.042 Overall order of reaction=.pdfshaktisinhgandhinaga
 
moles of H+ = 0.337 0.6303 = 0.2124 moles of OH.pdf
                     moles of H+ = 0.337  0.6303 = 0.2124 moles of OH.pdf                     moles of H+ = 0.337  0.6303 = 0.2124 moles of OH.pdf
moles of H+ = 0.337 0.6303 = 0.2124 moles of OH.pdfshaktisinhgandhinaga
 
lithium hydrogenphosphite LiH2PO3 lead(IV) hyd.pdf
                     lithium hydrogenphosphite  LiH2PO3  lead(IV) hyd.pdf                     lithium hydrogenphosphite  LiH2PO3  lead(IV) hyd.pdf
lithium hydrogenphosphite LiH2PO3 lead(IV) hyd.pdfshaktisinhgandhinaga
 
HClO3 HClO2 HClO HBrO Solution .pdf
                     HClO3  HClO2  HClO  HBrO Solution         .pdf                     HClO3  HClO2  HClO  HBrO Solution         .pdf
HClO3 HClO2 HClO HBrO Solution .pdfshaktisinhgandhinaga
 
d. PO43- as can acceppt H+ but cant donate H+. .pdf
                     d. PO43- as can acceppt H+ but cant donate H+. .pdf                     d. PO43- as can acceppt H+ but cant donate H+. .pdf
d. PO43- as can acceppt H+ but cant donate H+. .pdfshaktisinhgandhinaga
 
water + water = water 0.108 + 1x = 0.90(8 + x)0.8 + x = 7.2 + .pdf
water + water = water 0.108 + 1x = 0.90(8 + x)0.8 + x = 7.2 + .pdfwater + water = water 0.108 + 1x = 0.90(8 + x)0.8 + x = 7.2 + .pdf
water + water = water 0.108 + 1x = 0.90(8 + x)0.8 + x = 7.2 + .pdfshaktisinhgandhinaga
 
cooking of food, burning of paper, .pdf
                     cooking of food, burning of paper,               .pdf                     cooking of food, burning of paper,               .pdf
cooking of food, burning of paper, .pdfshaktisinhgandhinaga
 
The rst time they get one of the two sexes. After that they are wait.pdf
The rst time they get one of the two sexes. After that they are wait.pdfThe rst time they get one of the two sexes. After that they are wait.pdf
The rst time they get one of the two sexes. After that they are wait.pdfshaktisinhgandhinaga
 
System Thinking and Engineering-SolutionSystem Thinking and E.pdf
System Thinking and Engineering-SolutionSystem Thinking and E.pdfSystem Thinking and Engineering-SolutionSystem Thinking and E.pdf
System Thinking and Engineering-SolutionSystem Thinking and E.pdfshaktisinhgandhinaga
 
Solution1.) False (access the modules in the VBA editor (ALT+F11).pdf
Solution1.) False (access the modules in the VBA editor (ALT+F11).pdfSolution1.) False (access the modules in the VBA editor (ALT+F11).pdf
Solution1.) False (access the modules in the VBA editor (ALT+F11).pdfshaktisinhgandhinaga
 

More from shaktisinhgandhinaga (20)

3. Data Link Layer is the answer.This is because, SAPs act as an i.pdf
3. Data Link Layer is the answer.This is because, SAPs act as an i.pdf3. Data Link Layer is the answer.This is because, SAPs act as an i.pdf
3. Data Link Layer is the answer.This is because, SAPs act as an i.pdf
 
1. According to most surveys and reports the most infectious disease.pdf
1. According to most surveys and reports the most infectious disease.pdf1. According to most surveys and reports the most infectious disease.pdf
1. According to most surveys and reports the most infectious disease.pdf
 
1) D. Platelets are the blood cells which aid in blood clotting.2).pdf
1) D. Platelets are the blood cells which aid in blood clotting.2).pdf1) D. Platelets are the blood cells which aid in blood clotting.2).pdf
1) D. Platelets are the blood cells which aid in blood clotting.2).pdf
 
Vertical take-off and landing (VTOL) aircraft uses powered rotors fo.pdf
  Vertical take-off and landing (VTOL) aircraft uses powered rotors fo.pdf  Vertical take-off and landing (VTOL) aircraft uses powered rotors fo.pdf
Vertical take-off and landing (VTOL) aircraft uses powered rotors fo.pdf
 
The degree of ionization is influenced by the con.pdf
                     The degree of ionization is influenced by the con.pdf                     The degree of ionization is influenced by the con.pdf
The degree of ionization is influenced by the con.pdf
 
Problem 1 H2SO4 is diprotic, so it gives [H+] o.pdf
                     Problem 1  H2SO4 is diprotic, so it gives [H+] o.pdf                     Problem 1  H2SO4 is diprotic, so it gives [H+] o.pdf
Problem 1 H2SO4 is diprotic, so it gives [H+] o.pdf
 
only one because it exist only one isomer .pdf
                     only one because it exist only one isomer        .pdf                     only one because it exist only one isomer        .pdf
only one because it exist only one isomer .pdf
 
when 71.1 moles of carbon dioxide gas react with .pdf
                     when 71.1 moles of carbon dioxide gas react with .pdf                     when 71.1 moles of carbon dioxide gas react with .pdf
when 71.1 moles of carbon dioxide gas react with .pdf
 
NaCl HCl Cl2 Solution .pdf
                     NaCl  HCl  Cl2  Solution                   .pdf                     NaCl  HCl  Cl2  Solution                   .pdf
NaCl HCl Cl2 Solution .pdf
 
rate at t=0 is R=0.042 Overall order of reaction=.pdf
                     rate at t=0 is R=0.042 Overall order of reaction=.pdf                     rate at t=0 is R=0.042 Overall order of reaction=.pdf
rate at t=0 is R=0.042 Overall order of reaction=.pdf
 
moles of H+ = 0.337 0.6303 = 0.2124 moles of OH.pdf
                     moles of H+ = 0.337  0.6303 = 0.2124 moles of OH.pdf                     moles of H+ = 0.337  0.6303 = 0.2124 moles of OH.pdf
moles of H+ = 0.337 0.6303 = 0.2124 moles of OH.pdf
 
lithium hydrogenphosphite LiH2PO3 lead(IV) hyd.pdf
                     lithium hydrogenphosphite  LiH2PO3  lead(IV) hyd.pdf                     lithium hydrogenphosphite  LiH2PO3  lead(IV) hyd.pdf
lithium hydrogenphosphite LiH2PO3 lead(IV) hyd.pdf
 
HClO3 HClO2 HClO HBrO Solution .pdf
                     HClO3  HClO2  HClO  HBrO Solution         .pdf                     HClO3  HClO2  HClO  HBrO Solution         .pdf
HClO3 HClO2 HClO HBrO Solution .pdf
 
E)all of the abov .pdf
                     E)all of the abov                                .pdf                     E)all of the abov                                .pdf
E)all of the abov .pdf
 
d. PO43- as can acceppt H+ but cant donate H+. .pdf
                     d. PO43- as can acceppt H+ but cant donate H+. .pdf                     d. PO43- as can acceppt H+ but cant donate H+. .pdf
d. PO43- as can acceppt H+ but cant donate H+. .pdf
 
water + water = water 0.108 + 1x = 0.90(8 + x)0.8 + x = 7.2 + .pdf
water + water = water 0.108 + 1x = 0.90(8 + x)0.8 + x = 7.2 + .pdfwater + water = water 0.108 + 1x = 0.90(8 + x)0.8 + x = 7.2 + .pdf
water + water = water 0.108 + 1x = 0.90(8 + x)0.8 + x = 7.2 + .pdf
 
cooking of food, burning of paper, .pdf
                     cooking of food, burning of paper,               .pdf                     cooking of food, burning of paper,               .pdf
cooking of food, burning of paper, .pdf
 
The rst time they get one of the two sexes. After that they are wait.pdf
The rst time they get one of the two sexes. After that they are wait.pdfThe rst time they get one of the two sexes. After that they are wait.pdf
The rst time they get one of the two sexes. After that they are wait.pdf
 
System Thinking and Engineering-SolutionSystem Thinking and E.pdf
System Thinking and Engineering-SolutionSystem Thinking and E.pdfSystem Thinking and Engineering-SolutionSystem Thinking and E.pdf
System Thinking and Engineering-SolutionSystem Thinking and E.pdf
 
Solution1.) False (access the modules in the VBA editor (ALT+F11).pdf
Solution1.) False (access the modules in the VBA editor (ALT+F11).pdfSolution1.) False (access the modules in the VBA editor (ALT+F11).pdf
Solution1.) False (access the modules in the VBA editor (ALT+F11).pdf
 

Recently uploaded

Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 

Recently uploaded (20)

Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 

import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf

  • 1. import java.util.Scanner; class BinaryNode { BinaryNode left, right; int data; public BinaryNode() { left = null; right = null; data = 0; } public BinaryNode(int n) { left = null; right = null; data = n; } public void setLeft(BinaryNode n) { left = n; } public void setRight(BinaryNode n) { right = n; } public BinaryNode getLeft() { return left; } public BinaryNode getRight() { return right; }
  • 2. public void setData(int d) { data = d; } public int getData() { return data; } } class Binary { private BinaryNode root; public Binary() { root = null; } public boolean isEmpty() { return root == null; } public void insert(int data) { root = insert(root, data); } private BinaryNode insert(BinaryNode node, int data) { if (node == null) node = new BinaryNode(data); else { if (data <= node.getData()) node.left = insert(node.left, data); else node.right = insert(node.right, data); }
  • 3. return node; } public void delete(int k) { if (isEmpty()) System.out.println("Tree Empty"); else if (search(k) == false) System.out.println("Sorry "+ k +" is not present"); else { root = delete(root, k); System.out.println(k+ " deleted from the tree"); } } private BinaryNode delete(BinaryNode root, int k) { BinaryNode p, p2, n; if (root.getData() == k) { BinaryNode lt, rt; lt = root.getLeft(); rt = root.getRight(); if (lt == null && rt == null) return null; else if (lt == null) { p = rt; return p; } else if (rt == null) { p = lt; return p; } else {
  • 4. p2 = rt; p = rt; while (p.getLeft() != null) p = p.getLeft(); p.setLeft(lt); return p2; } } if (k < root.getData()) { n = delete(root.getLeft(), k); root.setLeft(n); } else { n = delete(root.getRight(), k); root.setRight(n); } return root; } public boolean search(int val) { return search(root, val); } private boolean search(BinaryNode r, int val) { boolean found = false; while ((r != null) && !found) { int rval = r.getData(); if (val < rval) r = r.getLeft(); else if (val > rval) r = r.getRight(); else {
  • 5. found = true; break; } found = search(r, val); } return found; } public void inorder() { inorder(root); } private void inorder(BinaryNode r) { if (r != null) { inorder(r.getLeft()); System.out.print(r.getData() +" "); inorder(r.getRight()); } } public void preorder() { preorder(root); } private void preorder(BinaryNode r) { if (r != null) { System.out.print(r.getData() +" "); preorder(r.getLeft()); preorder(r.getRight()); } } public void postorder() { postorder(root);
  • 6. } private void postorder(BinaryNode r) { if (r != null) { postorder(r.getLeft()); postorder(r.getRight()); System.out.print(r.getData() +" "); } } } public class BinarySearchTree { public static void main(String[] args) { Scanner scan = new Scanner(System.in); Binary Binary = new Binary(); System.out.println("Binary Search Tree Test "); char ch; do { System.out.println(" Binary Search Tree Operations "); System.out.println("1. insert "); System.out.println("2. delete"); System.out.println("3. search"); System.out.println("4. check empty"); int choice = scan.nextInt(); switch (choice) { case 1 : System.out.println("Enter integer element to insert"); Binary.insert( scan.nextInt() ); break; case 2 : System.out.println("Enter integer element to delete"); Binary.delete( scan.nextInt() );
  • 7. break; case 3 : System.out.println("Enter integer element to search"); System.out.println("Search result : "+ Binary.search( scan.nextInt() )); break; case 4 : System.out.println("Empty status = "+ Binary.isEmpty()); break; default : System.out.println("Wrong Entry "); break; } System.out.print(" Post order : "); Binary.postorder(); System.out.print(" Pre order : "); Binary.preorder(); System.out.print(" In order : "); Binary.inorder(); System.out.println(" Do you want to continue (Type y or n) "); ch = scan.next().charAt(0); } while (ch == 'Y'|| ch == 'y'); } } Solution import java.util.Scanner; class BinaryNode { BinaryNode left, right; int data; public BinaryNode() { left = null; right = null;
  • 8. data = 0; } public BinaryNode(int n) { left = null; right = null; data = n; } public void setLeft(BinaryNode n) { left = n; } public void setRight(BinaryNode n) { right = n; } public BinaryNode getLeft() { return left; } public BinaryNode getRight() { return right; } public void setData(int d) { data = d; } public int getData() { return data; } }
  • 9. class Binary { private BinaryNode root; public Binary() { root = null; } public boolean isEmpty() { return root == null; } public void insert(int data) { root = insert(root, data); } private BinaryNode insert(BinaryNode node, int data) { if (node == null) node = new BinaryNode(data); else { if (data <= node.getData()) node.left = insert(node.left, data); else node.right = insert(node.right, data); } return node; } public void delete(int k) { if (isEmpty()) System.out.println("Tree Empty"); else if (search(k) == false) System.out.println("Sorry "+ k +" is not present"); else {
  • 10. root = delete(root, k); System.out.println(k+ " deleted from the tree"); } } private BinaryNode delete(BinaryNode root, int k) { BinaryNode p, p2, n; if (root.getData() == k) { BinaryNode lt, rt; lt = root.getLeft(); rt = root.getRight(); if (lt == null && rt == null) return null; else if (lt == null) { p = rt; return p; } else if (rt == null) { p = lt; return p; } else { p2 = rt; p = rt; while (p.getLeft() != null) p = p.getLeft(); p.setLeft(lt); return p2; } } if (k < root.getData()) {
  • 11. n = delete(root.getLeft(), k); root.setLeft(n); } else { n = delete(root.getRight(), k); root.setRight(n); } return root; } public boolean search(int val) { return search(root, val); } private boolean search(BinaryNode r, int val) { boolean found = false; while ((r != null) && !found) { int rval = r.getData(); if (val < rval) r = r.getLeft(); else if (val > rval) r = r.getRight(); else { found = true; break; } found = search(r, val); } return found; } public void inorder() { inorder(root);
  • 12. } private void inorder(BinaryNode r) { if (r != null) { inorder(r.getLeft()); System.out.print(r.getData() +" "); inorder(r.getRight()); } } public void preorder() { preorder(root); } private void preorder(BinaryNode r) { if (r != null) { System.out.print(r.getData() +" "); preorder(r.getLeft()); preorder(r.getRight()); } } public void postorder() { postorder(root); } private void postorder(BinaryNode r) { if (r != null) { postorder(r.getLeft()); postorder(r.getRight()); System.out.print(r.getData() +" "); } }
  • 13. } public class BinarySearchTree { public static void main(String[] args) { Scanner scan = new Scanner(System.in); Binary Binary = new Binary(); System.out.println("Binary Search Tree Test "); char ch; do { System.out.println(" Binary Search Tree Operations "); System.out.println("1. insert "); System.out.println("2. delete"); System.out.println("3. search"); System.out.println("4. check empty"); int choice = scan.nextInt(); switch (choice) { case 1 : System.out.println("Enter integer element to insert"); Binary.insert( scan.nextInt() ); break; case 2 : System.out.println("Enter integer element to delete"); Binary.delete( scan.nextInt() ); break; case 3 : System.out.println("Enter integer element to search"); System.out.println("Search result : "+ Binary.search( scan.nextInt() )); break; case 4 : System.out.println("Empty status = "+ Binary.isEmpty()); break; default : System.out.println("Wrong Entry ");
  • 14. break; } System.out.print(" Post order : "); Binary.postorder(); System.out.print(" Pre order : "); Binary.preorder(); System.out.print(" In order : "); Binary.inorder(); System.out.println(" Do you want to continue (Type y or n) "); ch = scan.next().charAt(0); } while (ch == 'Y'|| ch == 'y'); } }