import java.util.Objects; class CovidVariant {     String Name;     String Unique_code;     CovidVariant left, right;     public CovidVariant(String name, String code) {         this.Name = name;         this.Unique_code = code;         left = right = null;     } } class VariantCollection {     private boolean compare_code(String code, String code_2) {         int year = Integer.parseInt(code.substring(0, 2));         int month = Integer.parseInt(code.substring(2, 4));         int date = Integer.parseInt(code.substring(4, 6));         int year_2 = Integer.parseInt(code_2.substring(0, 2));         int month_2 = Integer.parseInt(code_2.substring(2, 4));         int date_2 = Integer.parseInt(code_2.substring(4, 6));         if (year == year_2) {             if (month == month_2) {                 if (date > date_2) {                     return true;                 } else {                     return false;                 }             } else if (month > month_2) {                 return true;             } else {                 return false;             }         } else if (year > year_2) {             return true;         } else {             return false;         }     }     CovidVariant root;     VariantCollection() {         root = null;     }     void addVariant(CovidVariant cv) {         root = add(root, cv);     }     CovidVariant add(CovidVariant root, CovidVariant cv) {         if (root == null) {             root = new CovidVariant(cv.Name, cv.Unique_code);             return root;         }         if (!compare_code(cv.Unique_code, root.Unique_code)) {             root.left = add(root.left, cv);         } else if (compare_code(cv.Unique_code, root.Unique_code)) {             root.right = add(root.right, cv);         }         return root;     }     void inorder() {         inorderRec(root);     }     // Inorder Traversal     void inorderRec(CovidVariant root) {         if (root != null) {             inorderRec(root.left);             System.out.print("Name: " + root.Name + " code: " + root.Unique_code + "\n");             inorderRec(root.right);         }     }     void search(String code) {         search_Recursive(root, code);     }     CovidVariant search_Recursive(CovidVariant root, String code) {         if (root != null && Objects.equals(root.Unique_code, code)) {             System.out.println(root.Name);             return root;         }         assert root != null;         if (!compare_code(code, root.Unique_code)) {             root.left = search_Recursive(root.left, code);         } else if (compare_code(code, root.Unique_code)) {             root.right = search_Recursive(root.right, code);         }         return null;     } } public class Problem1 {     public static void main(String[] args) {         VariantCollection col = new VariantCollection();         col.addVariant(new CovidVariant("Alpha", "210201A"));         col.addVariant(new CovidVariant("Delta", "210311D"));         col.addVariant(new CovidVariant("Beta", "210311A"));         col.addVariant(new CovidVariant("Omicron", "211120D"));         col.inorder();         System.out.println("\n");         col.search("210311A"); // return the Beta variant //        col.previous("211120D"); // return the Delta variant     } }   Here is my full code that create BTS TREE HAVE FUNCTION INORDER(), SEARCH(), AND PREVIOUS()   I already done inorder(), and Search()   PLS, HELP ME CREATE FUNCTION PREVIOUS() in BTS TREE

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

import java.util.Objects;

class CovidVariant {
    String Name;
    String Unique_code;
    CovidVariant left, right;

    public CovidVariant(String name, String code) {
        this.Name = name;
        this.Unique_code = code;
        left = right = null;
    }
}

class VariantCollection {
    private boolean compare_code(String code, String code_2) {
        int year = Integer.parseInt(code.substring(0, 2));
        int month = Integer.parseInt(code.substring(2, 4));
        int date = Integer.parseInt(code.substring(4, 6));

        int year_2 = Integer.parseInt(code_2.substring(0, 2));
        int month_2 = Integer.parseInt(code_2.substring(2, 4));
        int date_2 = Integer.parseInt(code_2.substring(4, 6));

        if (year == year_2) {
            if (month == month_2) {
                if (date > date_2) {
                    return true;
                } else {
                    return false;
                }
            } else if (month > month_2) {
                return true;
            } else {
                return false;
            }
        } else if (year > year_2) {
            return true;
        } else {
            return false;
        }


    }

    CovidVariant root;

    VariantCollection() {
        root = null;
    }

    void addVariant(CovidVariant cv) {
        root = add(root, cv);
    }

    CovidVariant add(CovidVariant root, CovidVariant cv) {
        if (root == null) {
            root = new CovidVariant(cv.Name, cv.Unique_code);
            return root;
        }

        if (!compare_code(cv.Unique_code, root.Unique_code)) {
            root.left = add(root.left, cv);
        } else if (compare_code(cv.Unique_code, root.Unique_code)) {
            root.right = add(root.right, cv);
        }

        return root;
    }

    void inorder() {
        inorderRec(root);
    }

    // Inorder Traversal
    void inorderRec(CovidVariant root) {
        if (root != null) {
            inorderRec(root.left);
            System.out.print("Name: " + root.Name + " code: " + root.Unique_code + "\n");
            inorderRec(root.right);
        }
    }

    void search(String code) {
        search_Recursive(root, code);
    }

    CovidVariant search_Recursive(CovidVariant root, String code) {
        if (root != null && Objects.equals(root.Unique_code, code)) {
            System.out.println(root.Name);
            return root;
        }
        assert root != null;
        if (!compare_code(code, root.Unique_code)) {
            root.left = search_Recursive(root.left, code);
        } else if (compare_code(code, root.Unique_code)) {
            root.right = search_Recursive(root.right, code);
        }
        return null;
    }

}

public class Problem1 {
    public static void main(String[] args) {
        VariantCollection col = new VariantCollection();
        col.addVariant(new CovidVariant("Alpha", "210201A"));
        col.addVariant(new CovidVariant("Delta", "210311D"));
        col.addVariant(new CovidVariant("Beta", "210311A"));
        col.addVariant(new CovidVariant("Omicron", "211120D"));

        col.inorder();
        System.out.println("\n");
        col.search("210311A"); // return the Beta variant
//        col.previous("211120D"); // return the Delta variant
    }

}

 

Here is my full code that create BTS TREE HAVE FUNCTION INORDER(), SEARCH(), AND PREVIOUS()

 

I already done inorder(), and Search()

 

PLS, HELP ME CREATE FUNCTION PREVIOUS() in BTS TREE

ALL CODE I HAVE BEEN SHOWN ABOVE.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education