/**      * Returns the value associated with the given key in this symbol table.      * Takes advantage of the fact that the keys appear in increasing order to terminate      * early when possible.      *      * @param  key the key      * @return the value associated with the given key if the key is in the symbol table      *     and {@code null} if the key is not in the symbol table      * @throws IllegalArgumentException if {@code key} is {@code null}      */     public Value get(Key key) {         // TODO         // Change this code to make use of the fact the list is sorted to terminate early         // when possible.  Also, solve this using recursion.  To do this, you will need to         // add a recursive helper function that takes the front of a list (Node) as an argument         // and returns the correct value.         if (key == null) throw new IllegalArgumentException("argument to get() is null");          for (Node x = first; x != null; x = x.next) {             if (key.equals(x.key))                 return x.val;         }         return null;     } You may not use the keys() method in your code. You are modifying the implementation of the  methods, but not their interface or contract.

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 2RQ
icon
Related questions
Question

/**
     * Returns the value associated with the given key in this symbol table.
     * Takes advantage of the fact that the keys appear in increasing order to terminate
     * early when possible.
     *
     * @param  key the key
     * @return the value associated with the given key if the key is in the symbol table
     *     and {@code null} if the key is not in the symbol table
     * @throws IllegalArgumentException if {@code key} is {@code null}
     */
    public Value get(Key key) {
        // TODO
        // Change this code to make use of the fact the list is sorted to terminate early
        // when possible.  Also, solve this using recursion.  To do this, you will need to
        // add a recursive helper function that takes the front of a list (Node) as an argument
        // and returns the correct value.
        if (key == null) throw new IllegalArgumentException("argument to get() is null"); 
        for (Node x = first; x != null; x = x.next) {
            if (key.equals(x.key))
                return x.val;
        }
        return null;
    }

You may not use the keys() method in your code. You are modifying the implementation of the 
methods, but not their interface or contract.

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Linux
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning