Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

In JAVA implement the Comparable Key methods for unordered linked list ST on page 375. Do not implement the iterable. Please add comment and output

In JAVA implement the Comparable Key methods for unordered linked list ST on page 375. Do not implement the iterable. Please add comment and output showing that the code runs successfully.

image text in transcribed

image text in transcribed

public class ST, Value create an ordered symbol table void put(Key key, Value val) put key-value pair into the table (remove key from table if value is null) value paired with key (null ifkey is absent) remove key (and its value) from table is there a value paired with key? is the table empty? number of key-value pairs smallest key largest key largest key less than or equal to key smallest key greater than or equal to key number of keys less than key key of rankk delete smallest key delete largest key Value get(Key key) void delete(Key key) boolean contains (Key key) boolean isEmptyO) int size) Key minO Key maxCO Key floor(Key key) Key ceiling(Key key) int rank(Key key) Key select(int k) void deleteMinO void deleteMaxO int size(Key lo, Key h) number of keys in Clo..hi] Iterable keys ) all keys in the table, in sorted order API for a generic ordered symbol table 3.1 Symbol Tables 375 ORITHM 3.1 Sequential search (in an unordered linked list) ic class SequentialSearchST private Node first; private class Node pu // first node in the linked list // linked-list node Key key; Value val; Node next; public Node(Key key, Value val, Node next) this.keykey; this.valval; this.next next; public Value get(Key key) t // Search for key, return associated value. for (Node x first; x != nu11; x-x.next) if (key.equals(x.key)) // search hit // search miss return x.val; return null; // Search for key. Update value if found; grow table if new. first; x != nu 11; x = x.next) public void put(Key key, Value val) for (Node x if Ckey.equals (x.key)) x.val val; return;/Search hit: update val. first new Node(key, val, first); // Search miss: add new node. This ST implementation uses a private Node inner class to keep the keys and values in an unordered nked list. The get O implementation searches the list sequentially to find whether the key is in the e (and returns the associated value if so). The put O implementation also searches the list sequen- the table. If so, it updates the associated value; if not, it creates a ally to check whether the key is in node with the given key and value and inserts it at the beginning of the list. Implementations of keys O, and eager deleteO are left for exercises. public class ST, Value create an ordered symbol table void put(Key key, Value val) put key-value pair into the table (remove key from table if value is null) value paired with key (null ifkey is absent) remove key (and its value) from table is there a value paired with key? is the table empty? number of key-value pairs smallest key largest key largest key less than or equal to key smallest key greater than or equal to key number of keys less than key key of rankk delete smallest key delete largest key Value get(Key key) void delete(Key key) boolean contains (Key key) boolean isEmptyO) int size) Key minO Key maxCO Key floor(Key key) Key ceiling(Key key) int rank(Key key) Key select(int k) void deleteMinO void deleteMaxO int size(Key lo, Key h) number of keys in Clo..hi] Iterable keys ) all keys in the table, in sorted order API for a generic ordered symbol table 3.1 Symbol Tables 375 ORITHM 3.1 Sequential search (in an unordered linked list) ic class SequentialSearchST private Node first; private class Node pu // first node in the linked list // linked-list node Key key; Value val; Node next; public Node(Key key, Value val, Node next) this.keykey; this.valval; this.next next; public Value get(Key key) t // Search for key, return associated value. for (Node x first; x != nu11; x-x.next) if (key.equals(x.key)) // search hit // search miss return x.val; return null; // Search for key. Update value if found; grow table if new. first; x != nu 11; x = x.next) public void put(Key key, Value val) for (Node x if Ckey.equals (x.key)) x.val val; return;/Search hit: update val. first new Node(key, val, first); // Search miss: add new node. This ST implementation uses a private Node inner class to keep the keys and values in an unordered nked list. The get O implementation searches the list sequentially to find whether the key is in the e (and returns the associated value if so). The put O implementation also searches the list sequen- the table. If so, it updates the associated value; if not, it creates a ally to check whether the key is in node with the given key and value and inserts it at the beginning of the list. Implementations of keys O, and eager deleteO are left for exercises

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started