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

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

 
全局:
求问楼上的各位前辈啊,我最近刚开始学61B。。。这个作业,我在LockDList中几乎把DList的所有方法全部Override了(把方法中的DListNode改成LockDListNode。。。),才跑出来,是不是不太对?求指导
回复

使用道具 举报

全局:
jaly50 发表于 2014-6-12 13:05
我之前也有一样的问题!感觉是继承没有真正的搞懂!
后来我是这样改的:
除了作业里要求参数一定要是DL ...

求问楼主,我的做法跟你一样(几乎override了所有方法,修改返回和参数类型为LockDListNode),但是这样真的对么! 好像并没有用到继承的优势啊!是不是理解错继承了?
时间过了这么久,不好意思,不知你是否还记得呢?
回复

使用道具 举报

全局:
czbnlzd920706 发表于 2015-4-27 08:28
这次作业一开始轻视了。然后做到part3的时候才发现,有难度,而且难度不在于算法构造,而在于对于Java多态 ...

说得真棒!
回复

使用道具 举报

全局:
czbnlzd920706 发表于 2015-4-27 08:28
这次作业一开始轻视了。然后做到part3的时候才发现,有难度,而且难度不在于算法构造,而在于对于Java多态 ...

HI  看了你的回复,觉得很有收获,谢谢。 请教一下,那按照你的说法,测试代码应该有两处问题吧?
一处是你所说的LockDListNode sl1=sl1.front(); sl1应该改为DListNode。 另外一处是在下面,LockDListNode back=sl1.back(); 也应该改为DListNode把?这样back()这个方法也不用override了。。。。
回复

使用道具 举报

🔗
czbnlzd920706 2015-6-11 00:33:39 | 只看该作者
全局:
小A要当码农 发表于 2015-6-10 14:34
HI  看了你的回复,觉得很有收获,谢谢。 请教一下,那按照你的说法,测试代码应该有两处问题吧?
一处 ...

我记得下面的确还有一处,可改可不改,但应该改。具体忘了。。。
看见我一个多月前的总结好惭愧。。原来自己那么认真过。。。
回复

使用道具 举报

全局:
czbnlzd920706 发表于 2015-6-11 00:33
我记得下面的确还有一处,可改可不改,但应该改。具体忘了。。。
看见我一个多月前的总结好惭愧。。原来 ...

谢谢回复, 你得总结让我收获不少👍
回复

使用道具 举报

🔗
豆小凡 2015-6-17 14:32:18 | 只看该作者
全局:
这个折腾了很久,总算搞出来了
更多图片 小图 大图
组图打开中,请稍候......

评分

参与人数 1学分 +1 收起 理由
jaly50 + 1

查看全部评分

回复

使用道具 举报

🔗
smallmikko 2015-6-18 12:52:45 | 只看该作者
全局:
用了好久调试程序,给后来的同学一点建议,当然是个人经验
如果运行testLockDList的时候反复有java.lang.ClassCastException的run time error,建议overridden back() 和front(),然后在主程序里把node和back两个node定义为DListNode, 因为我也试过用cast把sl1.front()和sl1.back()的返回值cast成LockDListNode,保持node 和 back为LockDListNode,发现这样的情况下 LockDListNode node=(LockDListNode)sl1.front()右边的值传不到左边去(如果有高手能告诉我怎么传也可以)。当然这样的情况下,程序照常运行,而且因为node=null,所以remove的时候效果和出题的目的巧合的一致了
回复

使用道具 举报

🔗
mming1993 2015-6-19 16:00:49 | 只看该作者
全局:
Now we are testing DList.
Here is a list after insertBack 6, 9, 12: [  6  9  12  ]

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

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

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

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

Here is a list after insertBack 6, 7: [  6  7  ]
isEmpty() should be false. It is: false
length() should be 2. It is: 2
Here is the same list after insertFront(5): [  5  6  7  ]




Now we are testing LockDList.
Here is a list after insertBack 6, 9, 12: [  6  9  12  ]

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

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

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

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

Here is a list after insertBack 6, 7: [  6  7  ]
isEmpty() should be false. It is: false
length() should be 2. It is: 2
Here is the same list after insertFront(5): [  5  6  7  ]

评分

参与人数 1学分 +1 收起 理由
jaly50 + 1

查看全部评分

回复

使用道具 举报

🔗
althinking 2015-7-13 16:39:56 | 只看该作者
全局:
Homework 4


回复

使用道具 举报

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

本版积分规则

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