Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void writeTree(Tree tree) throws FileNotFoundException {
- long TreeStart = System.nanoTime() / 1000;
- JFileChooser chooser = new JFileChooser();
- System.out.println("Submit the an input File for the AVL Tree operations: ");
- chooser.showOpenDialog(null);
- File inputFile = chooser.getSelectedFile();
- Scanner in = new Scanner(inputFile);
- JFileChooser output = new JFileChooser();
- System.out.println("Select where to save the output file for the AVL Tree operations: ");
- output.showSaveDialog(null);
- PrintWriter out = new PrintWriter(output.getSelectedFile());
- while(in.hasNext()) {
- String methodCall = in.next();
- if(methodCall.equals("IN")) {
- int element = in.nextInt();
- tree.add(element);
- }
- else if(methodCall.equals("SC")) {
- int element = in.nextInt();
- out.println(tree.successor(element));
- }
- else if(methodCall.equals("PR")) {
- int element = in.nextInt();
- out.println(tree.predecessor(element));
- }
- else if(methodCall.equals("MI")) {
- out.println(tree.min());
- }
- else if(methodCall.equals("MA")) {
- out.println(tree.max());
- }
- else if(methodCall.equals("TR")) {
- out.println(tree.printInOrder());
- }
- else if(methodCall.equals("SR")) {
- int element = in.nextInt();
- out.println(tree.search(element));
- }
- else if(methodCall.equals("SE")) {
- int element = in.nextInt();
- out.println(tree.select(element));
- }
- else if(methodCall.equals("RA")) {
- int element = in.nextInt();
- out.println(tree.rank(element)); // does not work yet.
- }
- }
- long TreeEnd = System.nanoTime();
- long timeElapsed = TreeEnd - TreeStart;
- out.println("Time Elapsed in nanoseconds: " + timeElapsed / 1000);
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement