Advertisement
jeff69

Untitled

Oct 27th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. /// Driver Main
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.util.Scanner;
  5. import java.io.PrintWriter;
  6.  
  7. public class Main {
  8.    
  9.     public static void main(String[] args) throws FileNotFoundException {
  10.         File file = new File("input.txt");
  11.          PrintWriter pw = new PrintWriter("output.txt");
  12.     Scanner sc = new Scanner(file);
  13.         String line = sc.nextLine();
  14.         String [] ar  = line.split(" ");
  15.         int n = ar.length;
  16.         bst tree = new bst();
  17.         for(int i=0;i<n;i++)
  18.         {
  19.             Integer x = Integer.parseInt(ar[i]);
  20.             tree.insert(x);
  21.         }
  22.        
  23.             line = sc.nextLine();
  24.             Integer x = Integer.parseInt(line);
  25.            Node zbr = tree.find(x);
  26.            if(zbr != null)
  27.            {
  28.                 pw.println(x);
  29.            }
  30.           line = sc.nextLine();
  31.          
  32.            x = Integer.parseInt(line);
  33.         tree.remove(x);
  34.           line = sc.nextLine();
  35.          
  36.            x = Integer.parseInt(line);
  37.           tree.insert(x);
  38.          String order = tree.inorder_();
  39.         String []zn = order.split(" ");
  40.         for(String u: zn)
  41.             while(u.contains(" "))
  42.             u=u.replace(" ","");
  43.         for(String u : zn)
  44.             if(!u.equals(""))
  45.            pw.print(u+" ");
  46.         String newLine = System.getProperty("line.separator");
  47.         pw.print(newLine);
  48.         pw.println("BST:");
  49.         pw.print(tree.print());
  50.         pw.println("BSMT:");
  51.         pw.print(tree.mirror());
  52.         pw.close();
  53.        sc.close();
  54.     }
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement