Hello, I have a java program that is for an unordered dictionary, and we were to
ID: 3656368 • Letter: H
Question
Hello, I have a java program that is for an unordered dictionary, and we were told to make it sorted - I just don't know how I would go about doing it. Help would be greatly appreciated. Here is the program: import java.util.ArrayList; class UALDictionary implements Dictionary { private static final int defaultSize = 10; private ArrayList> list; // Constructors UALDictionary() { this(defaultSize); } UALDictionary(int sz) { list = new ArrayList>(sz); } public void clear() { list.clear(); } /** Insert an element: append to list */ public void insert(Key k, E e) { KVpair temp = new KVpair(k, e); list.add(temp); } /** Remove element with key k, return element */ public E remove(Key k) { E temp = find(k); if (temp != null) list.remove(new KVpair(k, temp)); return temp; } /** * Find k using sequential search * * @return Record with key value k */ public E find(Key k) { for (KVpair t : list) if (k.compareTo(t.key())==0) return t.value(); return null; // "k" does not appear in dictionary } public int size(){ return list.size(); } }Explanation / Answer
program you gave us is difficult to read as every thing got mixed up, please repost
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.