讲解:CIS 313, Intermediate Data StructuresJava、Java Java Binary Search Tree

CIS 313, Intermediate Data StructuresFall 2018CIS 313 Lab 2Due: November 1, 2018This lab involves implementing a Binary Search TreeOverviewFill out all of the methods in the provided skeleton code. You may add additional methods, butshould NOT add additional public elds to the BST class. You also should not change the name ofany of the classes or les. You will implement a working Binary Search Tree in the BST.java class.You will relay input commands in lab2.java using a scanner. In particular, you will implement thefollowing functionality:InsertionTo simplify things, we will not test your binary search tree with duplicate elements.Insertion should change one of the leaves of the tree from null to a node holding the inserted value.This should also preserve the ordering requirement that all nodes in the right side of a subtree aregreater than the value in the root of that subtree, and all elements in the left side are lesser thanthe value in the root of the subtree.DeletionWhen deleting a value, delete the node which contains that value from the tree.If said node has no children, simply remove it by setting its parent to point to null instead of it.If said node has one child, delete it by making its parent point to its child.If said node has two children, then replace it with its successor, and remove the successor from itsprevious location in the tree.The successor of a node is the left-most node in the node’s right subtree.If the value speci ed by delete does not exist in the tree, then the structure is left unchanged.FindFind takes an int and returns the node in the tree which holds that value.If no such node exists in the tree, return null.Traversals: preorder, post order, in orderPrint out the elements in a binary search tree, space separated.You should do this for the preorder, post order, and in ordered representation of the elements.Recommended StrategyCreate a print function to visualize the shape of trees.Create trees which should have the same shape, and trees which should have di erent shapes.This will also help you debug your other functions.1Input DescriptionThe input will be a text le, for example inSample.txt below will be provided. The rst line willcontain an integer N, which is the number of lines to follow. Each of the N lines contain a singleword specifying delete, insert, inorder, preorder, or postorder (and for insert and delete, also anumber).You should create an empty binary search tree (with root null), and then perform. a sequenceof actions on that tree.10insert 30insert 40insert 20insert 10inorderpreorderpostorderinsert 3调试CIS 313, Intermediate Data StructuresJava作业、Java Java Bina5delete 30inorderNote: When using an editor, you may also manually type in input to the command window.However, you will be tested with a le similar to inSample.txt.Output DescriptionThe only output will be from the traverse commands. Print each the data in each element in theBST separated by spaces in the correct order (depending on which traverse command was called).For example, using the sample input above, your program should output:10 20 30 4030 20 10 4010 20 40 3010 20 35 40Testing ProtocolWe will test your program in the same fashion as previous labs. We strongly suggest you test yourprogram in the following ways:While creating itWith inSample.txtWith the provided test.sh le found in /home/users/smergend/public/cs313/lab2/test.shon ix-dev.2GradingThis assignment will be graded as follows:Correctness 50%Your program compiles without errors (including the submitted les NOT containing package namesat the top. Delete the package name from the top of the les before you submit them): 10%Your program runs without errors: 10%Your program produces the correct output: 30%(5% for insertion, deletion, nd, and each traversal)Implementation 50%Your Binary Search Tree class implements all of the proper methods in O(n): 50%To earn points for implementation, your code must be clear enough for us to under-standFurther, you may not use any data structures from the Java standard library, theC foreign function interface, or arraysExtra Credit 20%To receive points for the extra credit you will create two Binary Search Trees based on given input,and then you must determine if they have the same shape:Create a new public class le called TreeCompareTreeCompare will be similar to lab2.java{ It will read in a list of commands from an input text le{ The input text le will create two di erent BSTs{ The input text le will start with a number N1{ Then N1 lines of insert commands will follow to create the rst BST{ Then there will be a line with a number N2{ Then N2 lines of insert commands will follow to create the second BSTAfter you have created the two BSTs, TreeCompare will compare the two treesIf the trees have the same shape, output &"The trees have the same shape.&"Otherwise, output &"The trees do not have the same shape.&"Here is an example of what the input text le may look like:insert 10insert 20insert 30insert 40insert 50insert 50insert 40insert 30insert 20insert 10The corresponding output would then be:The trees do not have the same shape.转自:http://ass.3daixie.com/2018110120083412.html

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

推荐阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,442评论 0 13
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,689评论 0 3
  • 在听了这些课之后,徐校长的课让我尤其印象深刻。作为一名乡村教师,条件艰苦,学生也有很多情况,但是老师为了学...
    公主岭422高悦阅读 187评论 1 0
  • 最近常想起小时候的一个场景,秋天的傍晚,天微黑了,我穿着单薄的衣服往家里去,感觉好冷,可能是干完活回家或者是玩好了...
    阳光洒洒阅读 111评论 2 0
  • 【关于花钱】 从年初月花销四五千~到年末每个月 一千几百的。 【关于享受】 嘿,我换上了肾,开始过上了 远离医院的...
    爱娇阅读 337评论 1 0