讲解:Java、Java、Dictionary、Java

No late assignments will be accepted.1 PartBThere is no partA for this homework.1.1 Symbol TableFor this problem, you are going to write a program SymbolTable.java which stores variables (just Strings)and associated values (of a generic type); such a data structure is used in all programming languages duringcompilation (e.g., Java) or interpretation (e.g., Python) to store information associated with variables. TheSymbolTable class will be generic in that it can store any kind of object as values (in the unit test, we willcreate two di erent symbol tables, one holding Integers and one holding Strings). The data structure usedto store the variables and values will be a linked list created from the following Node class:private class Node { // Node class for LLsString variable;Value value;Node next;public Node(String k, Value v, Node p) { // Constructorvariable = k; value = v; next = p;}}Node head = null;This class will be an \inner class&" of the SymbolTable class, that is, a class de ned inside another class,and all the information about the linked list will be private. Here is a template to get you started:SymbolTable.java. The linked list will be kept in ascending lexicographic order, (you will use compareTo(...)to compare the Strings when doing insertion). Note that the ordering used is the same as in a dictionary,and in fact, a symbol table IS a dictionary, where the \meaning&" of a symbol is the value associated witheach variable name.You may NOT use loops to process the linked lists, and hence you will have to write recursive algorithmsfor those methods that require moving down the linked list. The only loops that will occur in your programwill be those that I wrote in the Unit Tests.The interface for the symbol table is as follows (cut and paste into a new interface in your hw8 srcdirectory):/** File: Dictionary.java* Author: Wayne Snyder* Purpose: interface for dictionary in hw08*/package hw8;import java.util.Iterator;1public interface Dictionary {// NOTE: comments precede the method stub they specify//-- You do not need to make any changes to this file/** If the variable var is not in the symbol table, insert a new node containing var and val into* the linked list in ascending order (do NOT sort the list, but insert in order of the variable* field); if var is already in the table, then simply replace the existing value with the new* value val. The type Value is a generic type.*/public void put(String var, Value val);/** Return the value associated with the variable var, or throw the exception* if var is not in the table.*/public Value get(String var) throws KeyNotFoundException ;/** Return true or false, depending on whether var is in the table or not.*/public boolean contains(String var);/** Remove the node containing var from the table; if var is not in the table, do nothing.*/void delete(String var);/** Return the smallest variable in the lexicographic ordering (this will be in the first node in* the list); if the table is empty, throw the exception.*/public String min() throws KeyNotFoundException ;/** Similar to the previous, but return the largest entry, which will be in the last node in the* linked list.*/public String max() throws KeyNotFoundException ;/** If the table is empty or if var is smaller than the smallest entry, throw the exception; if var*is in* the table, return var; otherwise, return the largest variable which is less than var (the entry2* just before where var would be inserted into the table). If var is larger than the maximum key* in the table, return that maximum key. Do NOT insert var into the table if it is not there.* This is comparable to the mathematical function floor(...). [Hint: During the recursion, if* your current key equals var, then return it; else you should &"look ahead&" to see what* the next key is (checking first whether it is null!), and if the next key is larger than var,* or if there is no next key, your current key should be returned.]*/public String floor(String var) throws KeyNotFoundException ;/** If the table is empty or if var is larger than the largest entry, throw the exception; if var* is in the* table, return var; otherwise, return the smallest variable which is larger than var (the entry* just after where var would be inserted in代做Java程序、Java课程设计代写留学生、代写Dictionary编程、Java作业代做留学生to the table). (Do NOT insert var into the table!)* This is comparable to the mathematical function ceiling(...).*/public String ceiling(String var) throws KeyNotFoundException ;/** Return the &"rank&" of var, i.e., the number of entries in the table which are smaller* than var; the rank of variables which are in the table is calculated by counting 0, 1, 2,* starting at the first node (as if it were an array); if var is not in the table, then it is the* rank where var would be if it were inserted (do NOT insert var into the table).*/public int rank(String var);/** Return the variable which is at rank n in the linked list (starting the count at 0 with the* first node, as in an array). If the table is empty, or if n is not the rank of any element, i.e., it is negative or is* equal to or larger than the length of the linked list, throw the exception. You are essentially* just* returning the variable at location n in the list, but starting the count with 0 at the first* node.*/public String select(int n) throws KeyNotFoundException ;/* Remove the smallest (i.e., first) entry in the table; if the table is empty, do nothing. */public void deleteMin();/** Remove the largest (i.e., last) entry in the table; if the table is empty do nothing. Hint: you* can directly use a method from the Notes.....*/public void deleteMax();3/** Return the number of entries in the table (the length of the linked list); you should keep* track of this with a private variable size, which is updated when you remove* or add an entry.*/public int size();/** Return the number of entries in the table whose variables are in the range [lo .. hi], that is,* that are >= lo and ) as before, and third case(== of the rst character) in which you take one step forward in s for and one step down in the tree. Yoursearch ends when you hit null or run out of characters in s before hitting null. If you hit null and at thesame exact step as you run out of characters in s, you have found s in the tree; else, s is not in the tree.Our description above is not enough | see https://en.wikipedia.org/wiki/Ternary_search_treefor a nice example and details of insertion and search.In order for ternary search tree to make sense, we cannot allow insertion of two strings s1 and s2 thatare pre xes of each other; we will simply assume this never happens (one easy way to make sure this neverhappens is to have a special terminating character, such as ’n0’ at the end of every string; but in thishomework we won’t bother | we will simply not have test cases where one inserted strings is a pre x ofanother).Your job is to implement insertion, search, and an alphabetical-order iterator. The les to work with areTernarySearchTree.java, TernaryTreeNode.java, and TernarySearchTreeDriver.java. (Note that wecould make the node an inner class of the tree, like we did in some other examples, but we chose not to forreadability, because you may want to put code in the node class, and it will get hard to see what’s where.)2 Submission Checklist1Similar to your previous assignments, you will create a new package hw8 in Eclipse. Inside this package,all your Java les will reside. You will only submit the package hw8 to us. This package must contain thefollowing les only.SymbolTable.javaTernarySearchTree.javaTernaryTreeNode.javaThe rst line in every Java le must be package hw8;Be sure to do the following:You have read the Java Style. Guide for CS112 (linked on BlackBoard), and followed all guidelinesregarding format, layout, spaces, blank lines, and comments;1If you deviate from these instructions, we will penalize you 30% on the entire assignment. No late work will be accepted.If you are still not familiar with gSubmit, please stop by our o ce hours and we can help you with this.6You have removed or changed all comments inherited from my templates which do not relate to yoursolution;You have veri ed that your program satisfy all the performance tests in the templates.You can con rm that your assignment has been correctly2 submitted by typing this out: gsubmit cs112-lsYou can add as many helper methods (these must all be private), however, YOU CANNOT CHANGETHE METHOD NAMES OR CHANGE THE SIGNATURE OF THE REQUIRED METHODS IN THISASSIGNMENT. THIS WILL BREAK OUR TESTS AND YOU WILL RECEIVE ZERO.2You can read more about the gsubmit command by typing man gsubmit on the linux machines at BU转自:http://ass.3daixie.com/2018052158549078.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,874评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,102评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,676评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,911评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,937评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,935评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,860评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,660评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,113评论 1 308
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,363评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,506评论 1 346
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,238评论 5 341
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,861评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,486评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,674评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,513评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,426评论 2 352

推荐阅读更多精彩内容