Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Driver Main
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- import java.io.PrintWriter;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException {
- File file = new File("input.txt");
- PrintWriter pw = new PrintWriter("output.txt");
- Scanner sc = new Scanner(file);
- String line = sc.nextLine();
- String [] ar = line.split(" ");
- int n = ar.length;
- bst tree = new bst();
- for(int i=0;i<n;i++)
- {
- Integer x = Integer.parseInt(ar[i]);
- tree.insert(x);
- }
- line = sc.nextLine();
- Integer x = Integer.parseInt(line);
- Node zbr = tree.find(x);
- if(zbr != null)
- {
- pw.println(x);
- }
- line = sc.nextLine();
- x = Integer.parseInt(line);
- tree.remove(x);
- line = sc.nextLine();
- x = Integer.parseInt(line);
- tree.insert(x);
- String order = tree.inorder_();
- String []zn = order.split(" ");
- for(String u: zn)
- while(u.contains(" "))
- u=u.replace(" ","");
- for(String u : zn)
- if(!u.equals(""))
- pw.print(u+" ");
- String newLine = System.getProperty("line.separator");
- pw.print(newLine);
- pw.println("BST:");
- pw.print(tree.print());
- pw.println("BSMT:");
- pw.print(tree.mirror());
- pw.close();
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement