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

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

 
🔗
alexliao 2018-2-18 23:13:06 | 只看该作者
全局:
本帖最后由 alexliao 于 2018-2-18 23:15 编辑

DList:

file:\\D:\cs61b\hw4\DList.png
LockDlist:

file:\\D:\cs61b\hw4\LockDlist.png

回复

使用道具 举报

🔗
shineme7 2018-3-3 14:37:28 | 只看该作者
全局:
放假太颓废了,惭愧惭愧 >_<.
现在开学了,补回来

回复

使用道具 举报

🔗
bigworld 2018-3-3 16:37:44 | 只看该作者
全局:
本来打算寒假期间学晚的。。。
结果连java都没完。。开学恶补
【另外感谢楼主的test】



回复

使用道具 举报

🔗
allen_ig 2018-3-7 12:30:52 | 只看该作者
全局:

求加分~~
回复

使用道具 举报

🔗
Jerry_37 2018-3-8 10:53:45 | 只看该作者
全局:
hw4DList1

DList2

LockDList


评分

参与人数 1学分 +1 收起 理由
carry12345678 + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

全局:
终于写好了 碰到了两个问题
一是 head construct 之后没有指向自己QAQ
二是 一开始没有理解LockDList的模式
override时parameter时LockDListNode(wrong)应该是DListNode(right)同理,LockDlstNode的constructor中也是。
  1. Now we are testing DList.
  2. Here is a list after insertBack 6, 9, 12: [  6  9  12  ]

  3. Here is the same list after insertBack(15) and insertFront(3): [  3  6  9  12  15  ]

  4. front() should be 3. It is: 3
  5. front's next should be 6. It is: 6
  6. front's next's prev should be 3. It is: 3
  7. After remove the front, the front() should be 6. It is: 6
  8. After insertBefore() and insertAfter(), The first 3 nodes should be 5,6,8. The list is: [  5  6  8  9  12  15  ]

  9. Here is a list after construction: [  ]
  10. isEmpty() should be true. It is: true
  11. length() should be 0. It is: 0
  12. Here is a list after insertFront(3) to an empty list: [  3  ]
  13. Here is a list after insertBack(5) on an empty list: [  5  ]

  14. Here is a list after insertFront 3, 2, 1: [  1  2  3  ]
  15. isEmpty() should be false. It is: false
  16. length() should be 3. It is: 3
  17. Here is the same list after insertBack(4): [  1  2  3  4  ]

  18. Here is a list after insertBack 6, 7: [  6  7  ]
  19. isEmpty() should be false. It is: false
  20. length() should be 2. It is: 2
  21. Here is the same list after insertFront(5): [  5  6  7  ]
  22. Now we are testing LockDList.
  23. Here is a list after insertBack 6, 9, 12: [  6  9  12  ]

  24. Here is the same list after insertBack(15) and insertFront(3): [  3  6  9  12  15  ]

  25. front() should be 3. It is: 3
  26. front's next should be 6. It is: 6
  27. front's next's prev should be 3. It is: 3
  28. We lockNode front()= 3
  29. After remove the locked front, the front() should still be 3. It is: 3
  30. After remove the back, the back() should be 12. It is: 12
  31. After insertBefore(3) and insertAfter(3), The first 3 nodes should be 5,3,8. The list is: [  5  3  8  6  9  12  ]

  32. Here is a list after construction: [  ]
  33. isEmpty() should be true. It is: true
  34. length() should be 0. It is: 0
  35. Here is a list after insertFront(3) to an empty list: [  3  ]
  36. Here is a list after insertBack(5) on an empty list: [  5  ]

  37. Here is a list after insertFront 3, 2, 1: [  1  2  3  ]
  38. isEmpty() should be false. It is: false
  39. length() should be 3. It is: 3
  40. Here is the same list after insertBack(4): [  1  2  3  4  ]

  41. Here is a list after insertBack 6, 7: [  6  7  ]
  42. isEmpty() should be false. It is: false
  43. length() should be 2. It is: 2
  44. Here is the same list after insertFront(5): [  5  6  7  ]
  45. [code]Now we are testing LockDList.
  46. Here is a list after insertBack 6, 9, 12: [  6  9  12  ]

  47. Here is the same list after insertBack(15) and insertFront(3): [  3  6  9  12  15  ]

  48. front() should be 3. It is: 3
  49. front's next should be 6. It is: 6
  50. front's next's prev should be 3. It is: 3
  51. We lockNode front()= 3
  52. After remove the locked front, the front() should still be 3. It is: 3
  53. After remove the back, the back() should be 12. It is: 12
  54. After insertBefore(3) and insertAfter(3), The first 3 nodes should be 5,3,8. The list is: [  5  3  8  6  9  12  ]

  55. Here is a list after construction: [  ]
  56. isEmpty() should be true. It is: true
  57. length() should be 0. It is: 0
  58. Here is a list after insertFront(3) to an empty list: [  3  ]
  59. Here is a list after insertBack(5) on an empty list: [  5  ]

  60. Here is a list after insertFront 3, 2, 1: [  1  2  3  ]
  61. isEmpty() should be false. It is: false
  62. length() should be 3. It is: 3
  63. Here is the same list after insertBack(4): [  1  2  3  4  ]

  64. Here is a list after insertBack 6, 7: [  6  7  ]
  65. isEmpty() should be false. It is: false
  66. length() should be 2. It is: 2
  67. Here is the same list after insertFront(5): [  5  6  7  ]
复制代码
[/code]
个人理解 LockDListNode中是可以连着DListNode的 不知道对不对
回复

使用道具 举报

🔗
vincentli1 2018-3-20 17:37:17 | 只看该作者
全局:

交作业了! 这次的作业让我对override 有了更深的认识,一开始还小看了这次作业呢。
LockDList 中的LockNode和Remove方法实现的关键就在于LockDList中每个元素的static type 都是LockDListNode而不是其父类DListNode。这样才能保证将接口穿来的DListNode 能cast成LockDListNode且拥有isLocked field。
最简单的方法就是重写newNode方法,使其生成一个LockDListNode。这样的话其他所有能添加新node的方法最终都要调用newNode方法,从而保证了LockDList中每个元素的static type都是LockDListNode。
回复

使用道具 举报

🔗
shaonan 2018-3-21 23:35:35 | 只看该作者
全局:
vincentli1 发表于 2018-3-20 17:37
交作业了! 这次的作业让我对override 有了更深的认识,一开始还小看了这次作业呢。
LockDList 中的Lock ...

同学,想请教一下part 2. 不知道我这样理解对不对:当用Dlist实例化出一个list对象后,例如调用了list.remove(node)函数,这时并不能保证node是在list内的,所以这时仅仅把list的size减一,而list包含的node数量并没有改变。同理 其他函数也类似的可能只会改变list的size,而不会增加或减少list内node数量。

请问我的理解对吗?或者你能说说你的想法吗?多谢!

评分

参与人数 1大米 +10 收起 理由
kaiwhu + 10 哥们,我也一直搞不懂part2,你这个说法有.

查看全部评分

回复

使用道具 举报

🔗
vincentli1 2018-3-22 01:50:00 | 只看该作者
全局:
part2我也没想到太靠谱的只通过调用方法就搞乱整个链表的办法。不过我感觉你的想法站得住脚,程序不会遍历整个链表来确认node是否在表中。
回复

使用道具 举报

🔗
wangylcun 2018-4-2 20:20:31 | 只看该作者
全局:
本帖最后由 wangylcun 于 2018-4-2 20:28 编辑

交作业~





回复

使用道具 举报

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

本版积分规则

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