楼主: jaly50
跳转到指定楼层
上一主题 下一主题
收起左侧

Berkeley CS 61B Data Structures(in Java) Homework5 加分+讨论帖

 
🔗
gocong 2016-1-9 05:05:44 | 只看该作者
全局:
candy_shmily 发表于 2015-11-25 03:41
Part I is easy.
My test cases for Part II:
System.out.println("-------Test Insert-------");

您好,part II 我有个疑问。 set()构造函数怎么初始化呢? 我看了看github上code, 都是 new DList(); 但是我感觉不应该用多态吗,因为 set既可以用SList,也可以用DList。 但是 List 又是抽象类,没有构造函数,没法用new List();我这个地方很困惑。
回复

使用道具 举报

🔗
gocong 2016-1-9 05:10:03 | 只看该作者
全局:
lqwandyy 发表于 2015-11-23 20:21
An empty list should be [  ]: [  ]
l.isEmpty() should be true: true
l.length() should be 0: 0

您好,part II 我有个疑问。 set()构造函数怎么初始化呢? 我看了看github上code, 都是 new DList(); 但是我感觉不应该用多态吗,因为 set既可以用SList,也可以用DList。 但是 List 又是抽象类,没有构造函数,没法用new List();我这个地方很困惑。
回复

使用道具 举报

🔗
gocong 2016-1-14 07:48:05 | 只看该作者
全局:
gocong 发表于 2016-1-9 05:10
您好,part II 我有个疑问。 set()构造函数怎么初始化呢? 我看了看github上code, 都是 new DList() ...

好吧,我来自己回答吧,做完以后,我发现,List没有构造函数的原因就是作者想让你在这步来决定你用哪个List;所以如果你在这用new SList(), 那么set就是用SList完成的,用DList就是用DList完成的,但是对于用Set的人完全没影响,他不在乎你真正实现的是SList还是DList。这是你自己选择用List实现了算法的优化。如果有新的developer想用一个更好的List结构,他要做的就是创造一个新的List和ListNode ADT,然后在Set构造函数中引用new 新List();
回复

使用道具 举报

🔗
mingruiyrh 2016-1-14 11:12:18 | 只看该作者
全局:
交作业    part2写了还挺久的,用了88垅 Believers的test code,感谢~~~
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
mjtyumi 2016-1-19 18:11:14 | 只看该作者
全局:

难度一下就起来了。参考了 Github上面别人的思路,然后自己还写了很久
回复

使用道具 举报

🔗
frk 2016-1-22 23:15:05 | 只看该作者
全局:
本帖最后由 frk 于 2016-1-23 00:12 编辑

这次作业真是写了很久,对run time的match 花了较多时间,算法上的理解还是不够深入。通过这次作业,subclass和superclass的cast 也有了进一步的理解。
问题是, 在union 的时候,我直接用了写好的insert, 看了下github 发现 都是重新写的,进行判断后使用insertBefore()之类的method。不知道自己这样写符不符合要求。
加一下88垅的test code 测试结果




回复

使用道具 举报

🔗
hypsm 2016-1-28 00:20:30 | 只看该作者
全局:
part II 借用了楼上的测试代码


part I 测试数据比较长,就不贴图了:
  1. Dean-Mac:HW5 Dean$ java list.DList
  2. An empty list should be [  ]: [  ]
  3. l.isEmpty() should be true: true
  4. l.length() should be 0: 0
  5. Finding front node p of l.
  6. p.isValidNode() should be false: false
  7. p.item() should throw an exception, and did.
  8. p.setItem() should throw an exception, and did.
  9. p.next() should throw an exception, and did.
  10. p.prev() should throw an exception, and did.
  11. p.insertBefore() should throw an exception, and did.
  12. p.insertAfter() should throw an exception, and did.
  13. p.remove() should throw an exception, and did.
  14. Finding back node p of l.
  15. p.isValidNode() should be false: false
  16. p.item() should throw an exception, and did.
  17. p.setItem() should throw an exception, and did.
  18. p.next() should throw an exception, and did.
  19. p.prev() should throw an exception, and did.
  20. p.insertBefore() should throw an exception, and did.
  21. p.insertAfter() should throw an exception, and did.
  22. p.remove() should throw an exception, and did.
  23. l after insertFront(10) should be [  10  ]: [  10  ]
  24. l is a list of 3 elements: [  1  2  3  ]
  25. n.item() should be 1: 1
  26. n.item() should be 2: 2
  27. n.item() should be 2: 2
  28. n.item() should be 4: 4
  29. n.item() should be 3: 3
  30. n.item() should be 6: 6
  31. After doubling all elements of l: [  2  4  6  ]
  32. p.isValidNode() should be false: false
  33. p.item() should throw an exception, and did.
  34. p.setItem() should throw an exception, and did.
  35. p.next() should throw an exception, and did.
  36. p.prev() should throw an exception, and did.
  37. p.insertBefore() should throw an exception, and did.
  38. p.insertAfter() should throw an exception, and did.
  39. p.remove() should throw an exception, and did.
  40. n.item() should be 6: 6
  41. n.item() should be 12: 12
  42. n.item() should be 4: 4
  43. n.item() should be 8: 8
  44. n.item() should be 2: 2
  45. n.item() should be 4: 4
  46. After doubling all elements of l again: [  4  8  12  ]
  47. p.isValidNode() should be false: false
  48. p.item() should throw an exception, and did.
  49. p.setItem() should throw an exception, and did.
  50. p.next() should throw an exception, and did.
  51. p.prev() should throw an exception, and did.
  52. p.insertBefore() should throw an exception, and did.
  53. p.insertAfter() should throw an exception, and did.
  54. p.remove() should throw an exception, and did.
  55. Removing middle element (8) of l: 8
  56. l is now: [  4  12  ]
  57. p.isValidNode() should be false: false
  58. p.item() should throw an exception, and did.
  59. p.setItem() should throw an exception, and did.
  60. p.next() should throw an exception, and did.
  61. p.prev() should throw an exception, and did.
  62. p.insertBefore() should throw an exception, and did.
  63. p.insertAfter() should throw an exception, and did.
  64. p.remove() should throw an exception, and did.
  65. Removing end element (12) of l: 12
  66. l is now: [  4  ]
  67. p.isValidNode() should be false: false
  68. p.item() should throw an exception, and did.
  69. p.setItem() should throw an exception, and did.
  70. p.next() should throw an exception, and did.
  71. p.prev() should throw an exception, and did.
  72. p.insertBefore() should throw an exception, and did.
  73. p.insertAfter() should throw an exception, and did.
  74. p.remove() should throw an exception, and did.
  75. Removing first element (4) of l: 4
  76. l is now: [  ]
  77. p.isValidNode() should be false: false
  78. p.item() should throw an exception, and did.
  79. p.setItem() should throw an exception, and did.
  80. p.next() should throw an exception, and did.
  81. p.prev() should throw an exception, and did.
  82. p.insertBefore() should throw an exception, and did.
  83. p.insertAfter() should throw an exception, and did.
  84. p.remove() should throw an exception, and did.
复制代码
回复

使用道具 举报

🔗
buildgood 2016-1-31 23:47:02 | 只看该作者
全局:
终于写完了,这次花了挺长时间。后面intersect()没有考虑完全,改了挺久。
Part2用的测试代码跟楼上一样
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
hypsm 2016-2-1 06:02:34 | 只看该作者
全局:
buildgood 发表于 2016-1-31 23:47
终于写完了,这次花了挺长时间。后面intersect()没有考虑完全,改了挺久。
Part2用的测试代码跟楼上一样 ...

最近也在刷题中,可以一起讨论
回复

使用道具 举报

🔗
阿童木 2016-2-22 17:04:43 | 只看该作者
全局:
花了好长时间才调试好。参考了前面同学的测试代码。PART I




PART II


回复

使用道具 举报

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

本版积分规则

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