📣 Back to School开学季 - VIP通行证5折优惠!蓝莓、Offer多多同步优惠
楼主: complete_46
跳转到指定楼层
上一主题 下一主题
收起左侧

[公开课] Berkeley CS 61B Data Structures(in Java) Homework7 加分+讨论帖

 
全局:

懒得整个截下来了 确实挺麻烦的 做了一个早上
我觉得最难的地方是,三个keys的node更新了以后,就算他连接了原来的child1~4,还要把那些child的parent连接到新的node上。。。
另外每次重新连接的时候还要考虑child!=null
回复

使用道具 举报

🔗
 楼主| complete_46 2017-9-26 15:52:36 | 只看该作者
全局:
三年多了,看到这个贴子还有人顶,真是不容易,祝大家都有大OFFER拿
回复

使用道具 举报

🔗
ddy301 2017-10-22 00:35:11 | 只看该作者
全局:
hw7打卡






回复

使用道具 举报

🔗
elemist 2017-11-15 02:59:29 | 只看该作者
全局:



图片添加的有点丑陋。。。这次作业写的bug满地飞,花了很久debug..

回复

使用道具 举报

🔗
skyevil12 2017-12-9 22:21:26 | 只看该作者
全局:
最後在三個key的child.parent上卡了一下
解了

  1. D:\Git\DSA\CS61B\hw7>java -ea dict.Tree234

  2. Inserting 84.
  3. 84

  4. Inserting 7.
  5. 7 84

  6. Inserting 22.
  7. 7 22 84

  8. Inserting 95.
  9. (7)22(84 95)

  10. Inserting 50.
  11. (7)22(50 84 95)

  12. Inserting 11.
  13. (7 11)22(50 84 95)

  14. Inserting 37.
  15. (7 11)22(37 50)84(95)

  16. Inserting 60.
  17. (7 11)22(37 50 60)84(95)

  18. Inserting 1.
  19. (1 7 11)22(37 50 60)84(95)

  20. Inserting 23.
  21. (1 7 11)22(23 37)50(60)84(95)

  22. Inserting 16.
  23. ((1)7(11 16)22(23 37))50((60)84(95))

  24. Inserting 100.
  25. ((1)7(11 16)22(23 37))50((60)84(95 100))

  26. Inserting 28.
  27. ((1)7(11 16)22(23 28 37))50((60)84(95 100))

  28. Inserting 86.
  29. ((1)7(11 16)22(23 28 37))50((60)84(86 95 100))

  30. Inserting 49.
  31. ((1)7(11 16)22(23)28(37 49))50((60)84(86 95 100))

  32. Inserting 81.
  33. ((1)7(11 16)22(23)28(37 49))50((60 81)84(86 95 100))

  34. Inserting 51.
  35. ((1)7(11 16)22(23)28(37 49))50((51 60 81)84(86 95 100))

  36. Inserting 99.
  37. ((1)7(11 16)22(23)28(37 49))50((51 60 81)84(86)95(99 100))

  38. Inserting 75.
  39. ((1)7(11 16)22(23)28(37 49))50((51)60(75 81)84(86)95(99 100))

  40. Inserting 66.
  41. ((1)7(11 16)22(23)28(37 49))50((51)60(66 75 81))84((86)95(99 100))

  42. Inserting 4.
  43. ((1 4)7(11 16))22((23)28(37 49))50((51)60(66 75 81))84((86)95(99 100))

  44. Inserting 80.
  45. (((1 4)7(11 16))22((23)28(37 49)))50(((51)60(66)75(80 81))84((86)95(99 100)))

  46. Final tree:
  47.                100
  48.                99
  49.           95
  50.                86
  51.      84
  52.                81
  53.                80
  54.           75
  55.                66
  56.           60
  57.                51
  58. 50
  59.                49
  60.                37
  61.           28
  62.                23
  63.      22
  64.                16
  65.                11
  66.           7
  67.                4
  68.                1
复制代码
回复

使用道具 举报

🔗
村左秋树 2018-2-6 23:42:04 | 只看该作者
全局:
一亩三分地严打"顶""好贴""收藏了"之类的垃圾回复帖!被警告三次,系统会自动封杀ID!

想支持楼主,请点击帖子下方的"好苗""分享""收藏"键,酌情给楼主加大米(系统不扣你自己的分)。
积分不够看不了帖子,请参考论坛导航里的"帮助","新手提纲"里有攒积分指南
回复

使用道具 举报

🔗
村左秋树 2018-2-6 23:45:46 | 只看该作者
全局:

回复

使用道具 举报

🔗
allen_ig 2018-3-7 12:32:22 | 只看该作者
全局:
"C:\Program Files\Java\jdk-9.0.1\bin\java" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.2\lib\idea_rt.jar=51494:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.3.2\bin" -Dfile.encoding=UTF-8 -classpath "D:\GitHub\CS61b-Berkeley\out\production\Homework 7" dict.Tree234

Inserting 84.
84

Inserting 7.
7 84

Inserting 22.
7 22 84

Inserting 95.
(7)22(84 95)

Inserting 50.
(7)22(50 84 95)

Inserting 11.
(7 11)22(50 84 95)

Inserting 37.
(7 11)22(37 50)84(95)

Inserting 60.
(7 11)22(37 50 60)84(95)

Inserting 1.
(1 7 11)22(37 50 60)84(95)

Inserting 23.
(1 7 11)22(23 37)50(60)84(95)

Inserting 16.
((1)7(11 16)22(23 37))50((60)84(95))

Inserting 100.
((1)7(11 16)22(23 37))50((60)84(95 100))

Inserting 28.
((1)7(11 16)22(23 28 37))50((60)84(95 100))

Inserting 86.
((1)7(11 16)22(23 28 37))50((60)84(86 95 100))

Inserting 49.
((1)7(11 16)22(23)28(37 49))50((60)84(86 95 100))

Inserting 81.
((1)7(11 16)22(23)28(37 49))50((60 81)84(86 95 100))

Inserting 51.
((1)7(11 16)22(23)28(37 49))50((51 60 81)84(86 95 100))

Inserting 99.
((1)7(11 16)22(23)28(37 49))50((51 60 81)84(86)95(99 100))

Inserting 75.
((1)7(11 16)22(23)28(37 49))50((51)60(75 81)84(86)95(99 100))

Inserting 66.
((1)7(11 16)22(23)28(37 49))50((51)60(66 75 81))84((86)95(99 100))

Inserting 4.
((1 4)7(11 16))22((23)28(37 49))50((51)60(66 75 81))84((86)95(99 100))

Inserting 80.
(((1 4)7(11 16))22((23)28(37 49)))50(((51)60(66)75(80 81))84((86)95(99 100)))

Final tree:
               100
               99
          95
               86
     84
               81
               80
          75
               66
          60
               51
50
               49
               37
          28
               23
     22
               16
               11
          7
               4
               1

Process finished with exit code 0
回复

使用道具 举报

🔗
bigworld 2018-3-9 12:11:22 | 只看该作者
全局:
原来和大家遇到的都是同一个问题,new 节点 的child的parent指向。
另外感觉代码重复很厉害,已经把一部分重复代码写成了method,不过分类讨论好像又少不了(3-node是不是root, 是第几个child,它的parent的keys == 1 OR 2),最后插值时又要对当前节点分类讨论。if else遍地。精简的空间还是挺大的

Inserting 84.
84

Inserting 7.
7 84

Inserting 22.
7 22 84

Inserting 95.
(7)22(84 95)

Inserting 50.
(7)22(50 84 95)

Inserting 11.
(7 11)22(50 84 95)

Inserting 37.
(7 11)22(37 50)84(95)

Inserting 60.
(7 11)22(37 50 60)84(95)

Inserting 1.
(1 7 11)22(37 50 60)84(95)

Inserting 23.
(1 7 11)22(23 37)50(60)84(95)

Inserting 16.
((1)7(11 16)22(23 37))50((60)84(95))

Inserting 100.
((1)7(11 16)22(23 37))50((60)84(95 100))

Inserting 28.
((1)7(11 16)22(23 28 37))50((60)84(95 100))

Inserting 86.
((1)7(11 16)22(23 28 37))50((60)84(86 95 100))

Inserting 49.
((1)7(11 16)22(23)28(37 49))50((60)84(86 95 100))

Inserting 81.
((1)7(11 16)22(23)28(37 49))50((60 81)84(86 95 100))

Inserting 51.
((1)7(11 16)22(23)28(37 49))50((51 60 81)84(86 95 100))

Inserting 99.
((1)7(11 16)22(23)28(37 49))50((51 60 81)84(86)95(99 100))

Inserting 75.
((1)7(11 16)22(23)28(37 49))50((51)60(75 81)84(86)95(99 100))

Inserting 66.
((1)7(11 16)22(23)28(37 49))50((51)60(66 75 81))84((86)95(99 100))

Inserting 4.
((1 4)7(11 16))22((23)28(37 49))50((51)60(66 75 81))84((86)95(99 100))

Inserting 80.
(((1 4)7(11 16))22((23)28(37 49)))50(((51)60(66)75(80 81))84((86)95(99 100)))

Final tree:
               100
               99
          95
               86
     84
               81
               80
          75
               66
          60
               51
50
               49
               37
          28
               23
     22
               16
               11
          7
               4
               1
回复

使用道具 举报

🔗
shineme7 2018-3-28 12:14:31 | 只看该作者
全局:
继续学习,发现编程真的是很强调逻辑。首先Track down the whole tree, split 3-key node into 2 node, move the middle element to the parent node. If the parent node is null, then creat a new one.  针对nodekeys 的数量进行分类讨论,同时设置position变量用于判断key的插入位置。如果position==0,则插入第一位,以此类推。


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表