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

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

 
🔗
切梨 2017-8-22 16:33:22 | 只看该作者
全局:
来挣学分啦~~~
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
关键39 2017-8-26 14:31:10 | 只看该作者
全局:
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊好难的啊啊啊啊啊
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
关键39 2017-8-26 14:32:15 | 只看该作者
全局:
超级感谢首页的大佬!!!你们超级棒!
回复

使用道具 举报

🔗
elemist 2017-8-31 02:55:00 | 只看该作者
全局:
用了GitHub上的测试点。
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

全局:

分享一下我的思路吧,不知道其他人是怎么做的
-----以下可能有剧透----------------------------------------------
首先,LockDListNode 继承了 DListNode, 他的构造器直接调用super的就可以了,它有一个boolean的lock参数,但是我把它设置为private,只能通过setter和getter方法,并且只能set为true,不能set为false,因此一旦locked就再也不能删除了
重点是LockDList,这里需要override的方法是newNode,remove,然后再多造一个lockNode的方法就可以了。
我觉得这里比较tricky的地方是,我不知道要不要重写它的head,我感觉这也不算是老师课上说的field shadowing,因为我把head弄成了 LockDListNode,相当于一个新的参数了,因为要求的是“LockDListNodes are always used in LockDLists (instead of DListNodes”,所以我强行重新弄了一个head。但是既然整个过程中不会用到head,那么其实也不需要另外重写head.


在我的LockDList中,有这么几个invariants:
1. 通过newNode构造的都是LockDListNode
2. LockDList的所有方法都要用到newNode

这样就保证了 我们只需要override newNode方法,就可以确保在这个LockDList中的所有node的类型就是LockDListNode
所以,即使DList中的方法用的参数是DListNode类型,但那只是一个static type,我们最后输出的对象其本质的类型都是LockDListNode(因为每个都用到了newNode,所以每一个新的node都是LockDListNode)
不知道这样是不是说的不够清楚。。。
但是这次作业真的让我收获很多,子类和父类的各种关系,构造器的使用之类的,贴图就贴了Lock的那个test





WechatIMG3.jpeg (104.57 KB, 下载次数: 0)

WechatIMG3.jpeg
回复

使用道具 举报

🔗
Victor vshbd 2017-9-13 21:30:10 | 只看该作者
全局:
打卡打卡,学到了static type dynam type, compile time和run time 不是一个机制, override要signature完全一样。 学到了好多!求学分 求学分
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
Victor vshbd 2017-9-13 21:34:23 | 只看该作者
全局:
打卡打卡,学到了static type dynam type, compile time和run time 不是一个机制, override要signature完全一样。 学到了好多!求学分 求学分
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
psychewww 2017-9-22 02:26:15 | 只看该作者
全局:
  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  ]
复制代码
  1. Now we are testing LockDList.
  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. We lockNode front()= 3
  8. After remove the locked front, the front() should still be 3. It is: 3
  9. After remove the back, the back() should be 12. It is: 12
  10. After insertBefore(3) and insertAfter(3), The first 3 nodes should be 5,3,8. The list is: [  5  3  8  6  9  12  ]

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

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

  20. Here is a list after insertBack 6, 7: [  6  7  ]
  21. isEmpty() should be false. It is: false
  22. length() should be 2. It is: 2
  23. Here is the same list after insertFront(5): [  5  6  7  ]
复制代码
打卡打卡打卡!


回复

使用道具 举报

🔗
ddy301 2017-9-27 00:07:42 | 只看该作者
全局:
打卡,多态和继承还是有点晕。




回复

使用道具 举报

🔗
shi198 2017-11-29 12:00:27 | 只看该作者
全局:
这个星期有点懒 现在才把作业写完 感谢各位大神提供的test file写起来方便多了part1:

part2:



回复

使用道具 举报

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

本版积分规则

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