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

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

 
🔗
mming1993 2015-6-22 23:24:40 | 只看该作者
全局:
An empty list should be [  ]: [  ]
l.isEmpty() should be true: true
l.length() should be 0: 0
Finding front node p of l.
p.isValidNode() should be false: false
p.item() should throw an exception, and did.
p.setItem() should throw an exception, and did.
p.next() should throw an exception, and did.
p.prev() should throw an exception, and did.
p.insertBefore() should throw an exception, and did.
p.insertAfter() should throw an exception, and did.
p.remove() should throw an exception, and did.
Finding back node p of l.
p.isValidNode() should be false: false
p.item() should throw an exception, and did.
p.setItem() should throw an exception, and did.
p.next() should throw an exception, and did.
p.prev() should throw an exception, and did.
p.insertBefore() should throw an exception, and did.
p.insertAfter() should throw an exception, and did.
p.remove() should throw an exception, and did.
l after insertFront(10) should be [  10  ]: [  10  ]
l is a list of 3 elements: [  1  2  3  ]
n.item() should be 1: 1
n.item() should be 2: 2
n.item() should be 2: 2
n.item() should be 4: 4
n.item() should be 3: 3
n.item() should be 6: 6
After doubling all elements of l: [  2  4  6  ]
p.isValidNode() should be false: false
p.item() should throw an exception, and did.
p.setItem() should throw an exception, and did.
p.next() should throw an exception, and did.
p.prev() should throw an exception, and did.
p.insertBefore() should throw an exception, and did.
p.insertAfter() should throw an exception, and did.
p.remove() should throw an exception, and did.
n.item() should be 6: 6
n.item() should be 12: 12
n.item() should be 4: 4
n.item() should be 8: 8
n.item() should be 2: 2
n.item() should be 4: 4
After doubling all elements of l again: [  4  8  12  ]
p.isValidNode() should be false: false
p.item() should throw an exception, and did.
p.setItem() should throw an exception, and did.
p.next() should throw an exception, and did.
p.prev() should throw an exception, and did.
p.insertBefore() should throw an exception, and did.
p.insertAfter() should throw an exception, and did.
p.remove() should throw an exception, and did.
Removing middle element (8) of l: 8
l is now: [  4  12  ]
p.isValidNode() should be false: false
p.item() should throw an exception, and did.
p.setItem() should throw an exception, and did.
p.next() should throw an exception, and did.
p.prev() should throw an exception, and did.
p.insertBefore() should throw an exception, and did.
p.insertAfter() should throw an exception, and did.
p.remove() should throw an exception, and did.
Removing end element (12) of l: 12
l is now: [  4  ]
p.isValidNode() should be false: false
p.item() should throw an exception, and did.
p.setItem() should throw an exception, and did.
p.next() should throw an exception, and did.
p.prev() should throw an exception, and did.
p.insertBefore() should throw an exception, and did.
p.insertAfter() should throw an exception, and did.
p.remove() should throw an exception, and did.
Removing first element (4) of l: 4
l is now: [  ]
p.isValidNode() should be false: false
p.item() should throw an exception, and did.
p.setItem() should throw an exception, and did.
p.next() should throw an exception, and did.
p.prev() should throw an exception, and did.
p.insertBefore() should throw an exception, and did.
p.insertAfter() should throw an exception, and did.
p.remove() should throw an exception, and did.



Set s = [  3  4  ]
Set s2 = [  4  5  ]
Set s3 = [  3  5  8  ]
After s.union(s2), s = [  3  4  5  ]
After s.intersect(s3), s = [  3  5  ]
s.cardinality() = 2
感觉算法做复杂了。。。
回复

使用道具 举报

🔗
小小溪 2015-6-24 12:06:49 | 只看该作者
全局:
感觉partII最好还是自己加几个test
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
czbnlzd920706 2015-6-25 04:41:18 | 只看该作者
全局:
smallmikko 发表于 2015-6-21 08:47
请问您后来是怎么把DList l这个值赋到每个node.myList上的?大概的思路什么样,因为不管是哪种insert,ar ...

不好意思刚看到。。貌似是直接强制转换吧。记得不是很清楚了
回复

使用道具 举报

🔗
smallmikko 2015-6-26 11:57:17 | 只看该作者
全局:
小A要当码农 发表于 2015-6-18 22:28
求问大神 能解释得再详细一些么?
谢谢!

本学弱猜想是建立一个新的list 对象,利用多态性,去调用list子类的override过的一些函数
回复

使用道具 举报

🔗
豆小凡 2015-7-6 19:57:16 | 只看该作者
全局:
写了好久。。。一张图放不下分了2张,求加分
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
althinking 2015-7-17 13:22:14 | 只看该作者
全局:
本帖最后由 althinking 于 2015-7-17 13:25 编辑

Homework 5Part 1

Part 2


part 2的intersect()要考虑多种边界条件。比如空集的情况;s1.intersect(s2)时,s2触发了exception,s1能不能继续把剩下的元素删掉。
下面是我的test cases,抛砖引玉。
  1.   public static void main(String[] argv) {
  2.     System.out.println("Testing insert()");
  3.     Set s = new Set();
  4.     s.insert(new Integer(3));
  5.     s.insert(new Integer(4));
  6.     s.insert(new Integer(3));
  7.     System.out.println("Set s should be { 3 4 }: " + s);

  8.     Set s2 = new Set();
  9.     s2.insert(new Integer(4));
  10.     s2.insert(new Integer(5));
  11.     s2.insert(new Integer(5));
  12.     System.out.println("Set s2 should be { 4 5 }: " + s2);

  13.     Set s3 = new Set();
  14.     s3.insert(new Integer(5));
  15.     s3.insert(new Integer(3));
  16.     s3.insert(new Integer(8));
  17.     System.out.println("Set s3 should be { 3 5 8 }: " + s3);

  18.     System.out.println();
  19.     System.out.println("Tesing union()");
  20.     s.union(s2);
  21.     System.out.println("After s.union(s2), s should be { 3 4 5 }: " + s);
  22.     s2.union(s3);
  23.     System.out.println("After s2.union(s3), s2 should be { 3 4 5 8 }: " + s2);
  24.     Set s4 = new Set();
  25.     System.out.println("Empty set s4 = " + s4);
  26.     s.union(s4);
  27.     System.out.println("After s.union(s4), s should be { 3 4 5 }: " + s);
  28.     s4.union(s);
  29.     System.out.println("After s4.union(s), s4 should be { 3 4 5 }: " + s4);

  30.     System.out.println();
  31.     System.out.println("Tesing intersect()");
  32.     Set s5 = new Set();
  33.     Set s6 = new Set();
  34.     s6.insert(new Integer(1));
  35.     s5.intersect(s6);
  36.     System.out.println("{}.intersect({1}) should be { }: " + s5);
  37.     s6.intersect(s5);
  38.     System.out.println("{1}.intersect({}) should be { }: " + s6);
  39.     s6.insert(new Integer(1));
  40.     Set s7 = new Set();
  41.     s7.insert(new Integer(1));
  42.     s7.insert(new Integer(2));
  43.     s6.intersect(s7);
  44.     System.out.println("{1}.intersect({1 2}) should be { 1 }: " + s6);
  45.     s6.insert(new Integer(2));
  46.     s6.insert(new Integer(3));
  47.     s6.intersect(s7);
  48.     System.out.println("{1 2 3}.intersect({1 2}) should be { 1 2 }: " + s6);
  49.     s6.insert(new Integer(3));
  50.     s6.insert(new Integer(5));
  51.     s7.insert(new Integer(4));
  52.     s7.insert(new Integer(7));
  53.     s7.intersect(s6);
  54.     System.out.println("{1 2 4 7}.intersect({1 2 3 5}) should be { 1 2 }: " + s7);

  55.     System.out.println();
  56.     System.out.println("Tesing cardinality()");
  57.     System.out.println("s.cardinality() should be 3: " + s.cardinality());
  58.     System.out.println("s4.cardinality() should be 3: " + s4.cardinality());
  59.     System.out.println("s5.cardinality() should be 0: " + s5.cardinality());
  60.     System.out.println("s6.cardinality() should be 4: " + s6.cardinality());
  61.     System.out.println("s7.cardinality() should be 2: " + s7.cardinality());
  62.   }
复制代码

评分

参与人数 5大米 +18 学分 +1 收起 理由
tkft + 5 给你点个赞!
youngyang + 5 感谢分享!
213123418 + 3 感谢分享!
jigsaw_Becky + 5 感谢分享!
AveMaleficum + 1

查看全部评分

回复

使用道具 举报

🔗
lyc1994 2015-7-19 21:32:52 | 只看该作者
全局:
上传作业,本次作业要多谢Enirinth大神提供的算法思路,一开始自己用的方法太烦了。因为上传限制就只上传part2的部分吧。。

homework5_part1.JPG (21.17 KB, 下载次数: 0)

homework5_part1.JPG

评分

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

查看全部评分

回复

使用道具 举报

🔗
gh603 2015-7-22 14:45:43 | 只看该作者
全局:
Homework 5:
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
edwin1992 2015-7-27 13:04:33 | 只看该作者
全局:
请问Set.java应该放在哪里啊?我用的Eclipse,感觉应该放在list 这个package之外,我又新建了个project,然后在里面创建Set.java,但是就报错啊。。。谢谢了,cs基础薄弱
回复

使用道具 举报

🔗
soulstephen 2015-7-27 23:51:17 | 只看该作者
全局:
补交一下hw5^ ^





回复

使用道具 举报

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

本版积分规则

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