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

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

 
🔗
iamash 2015-10-14 08:44:40 | 只看该作者
全局:
L.r_yoga 发表于 2015-10-14 08:36
part I 太长就没传截图,part II见下~
果然基础弱>_

有错误的话就会throw exception,程序就停止了。
就像经常会出现的NullPointerException
回复

使用道具 举报

🔗
jigsaw_Becky 2015-11-8 16:12:53 | 只看该作者
全局:
edwin1992 发表于 2015-7-27 13:04
请问Set.java应该放在哪里啊?我用的Eclipse,感觉应该放在list 这个package之外,我又新建了个project,然 ...

eclipse每次建立一个java project就有一个default package,那里面就放的是Set.java,然后你在你的项目src那里create new package,就可以放list package了!
其实你在workspace文件夹里面也看的出来,src文件夹里面是一个set.java程序和一个list文件夹,list文件夹里面再放的其他java 程序
回复

使用道具 举报

🔗
jigsaw_Becky 2015-11-8 17:29:37 | 只看该作者
全局:
本帖最后由 jigsaw_Becky 于 2015-11-8 17:32 编辑

虽然运行结果和答案一样,但是我知道我好些边界条件没有考虑到!!!!头都昏了!!!每次也只能考虑到最普通的情况,一想到各种特殊情况就头脑混乱!!!怎么办啊??!!!!
开始还打算在set.java里调用head prev next这些,后面才发现,原来它们是protected,由于不在一个package里面,所以不能用。囧囧囧囧囧囧囧囧囧囧囧囧囧囧
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
ohmyonetwo 2015-11-11 15:08:52 | 只看该作者
全局:
Homework5凑字数啊
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
lqwandyy 2015-11-23 20:21:00 | 只看该作者
全局:
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.
成功构建 (总时间: 3 秒)
回复

使用道具 举报

🔗
lqwandyy 2015-11-24 00:09:27 | 只看该作者
全局:
终于弄出来了。。。

hw5.jpg (18.19 KB, 下载次数: 0)

hw5.jpg
回复

使用道具 举报

全局:
Part I is easy.
My test cases for Part II:
System.out.println("-------Test Insert-------");
Set s = new Set();
System.out.println("Empty set s should be {  } and s = " + s);
s.insert(new Integer(3));
System.out.println("Insert 3, then Set s should be { 3 } and s = " + s);
s.insert(new Integer(6));
System.out.println("Insert 6, then Set s should be { 3  6 } and s = " + s);
s.insert(new Integer(3));
System.out.println("Insert 3, then Set s should be { 3  6 } and s = " + s);
s.insert(new Integer(5));
System.out.println("Insert 5, then Set s should be { 3  5  6 } and s = " + s);
System.out.println();
Set s2 = new Set();
s2.insert(new Integer(4));
s2.insert(new Integer(5));
s2.insert(new Integer(5));
System.out.println("Insert 4, 5, 5 to empty Set s2, then s2 should be { 4  5 } and s2 = " + s2);
Set s3 = new Set();
s3.insert(new Integer(5));
s3.insert(new Integer(3));
s3.insert(new Integer(8));
System.out.println("Insert 5, 3, 8 to empty Set s3, then s3 should be { 3  5  8 } and s3 = " + s3);
System.out.println("-------Test union-------");
s.union(s2);
System.out.println("After s.union(s2), s should be { 3  4  5  6 } and s = " + s);
Set s4 = new Set();
s.union(s4);
System.out.println("After s unions empty Set s4, s should be { 3  4  5  6 } and s = " + s);
s4.union(s2);
System.out.println("After s4 unions s2, s4 should be { 4  5 } and s4 = " + s4);
System.out.println("-------Test intersect-------");
s.intersect(s3);
System.out.println("After s.intersect(s3), s should be { 3  5 } and s = " + s);
Set s5 = new Set();
s.intersect(s5);
System.out.println("After s intersects empty Set s5, s should be {  } and s = " + s);
s5.intersect(s);
System.out.println("After s5.intersect(s), s5 should be {  } and s5 = " + s5);
System.out.println("-------Test cardinality-------");
System.out.println("Set s3.cardinality() should be 3 and s3.cardinality() = " + s3.cardinality());
System.out.println("Set s.cardinality() should be 0 and s.cardinality() = " + s.cardinality());
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
Believers 2015-12-3 22:59:12 | 只看该作者
全局:
本帖最后由 Believers 于 2015-12-3 23:14 编辑

这次作业写了挺久的……partII里面的遇到各种bug,果然基础差
另外,我的PartII部分测试代码
  1.     Set s = new Set();
  2.     s.insert(new Integer(3));
  3.     s.insert(new Integer(4));
  4.     s.insert(new Integer(3));
  5.     System.out.println("Set s = " + s);

  6.     Set s2 = new Set();
  7.     s2.insert(new Integer(4));
  8.     s2.insert(new Integer(5));
  9.     s2.insert(new Integer(5));
  10.     System.out.println("Set s2 = " + s2);

  11.     Set s3 = new Set();
  12.     s3.insert(new Integer(5));
  13.     s3.insert(new Integer(3));
  14.     s3.insert(new Integer(8));
  15.     System.out.println("Set s3 = " + s3);


  16.     s.union(s2);
  17.     System.out.println("After s.union(s2), s = " + s);

  18.     s.union(s3);
  19.     System.out.println("After s.union(s3), s = " + s);


  20.     Set s4 = new Set();
  21.     s4.insert(new Integer(3));
  22.     s4.insert(new Integer(2));
  23.     s4.insert(new Integer(1));
  24.     System.out.println("Set s4 = " + s4);

  25.     Set s5 = new Set();
  26.     System.out.println("Set s5 = " + s5);

  27.     s4.union(s5);
  28.     System.out.println("After s4.union(s5), s4 = " + s4);

  29.     Set s6 = new Set();
  30.     System.out.println("Set s6 = " + s6);

  31.     Set s7 = new Set();
  32.     s7.insert(new Integer(3));
  33.     s7.insert(new Integer(2));
  34.     s7.insert(new Integer(1));
  35.     System.out.println("Set s7 = " + s7);

  36.     s6.union(s7);
  37.     System.out.println("After s6.union(s7), s6 = " + s6);

  38.     s6.intersect(s4);
  39.     System.out.println("After s6.intersect(s4), s6 = " + s6);

  40.     Set s8 = new Set();
  41.     System.out.println("Set s8 = " + s8);

  42.     Set s9 = new Set();
  43.     s9.insert(new Integer(3));
  44.     s9.insert(new Integer(2));
  45.     s9.insert(new Integer(1));
  46.     System.out.println("Set s9 = " + s9);

  47.     Set s10 = new Set();
  48.     System.out.println("Set s10 = " + s10);

  49.     s8.intersect(s9);
  50.     System.out.println("After s8.intersect(s9), s8 = " + s8);

  51.     s10.intersect(s8);
  52.     System.out.println("After s10.intersect(s8), s10 = " + s10);

  53.     s10.intersect(s9);
  54.     System.out.println("After s10.intersect(s9), s10 = " + s10);

  55.     Set s11 = new Set();
  56.     s11.insert(new Integer(4));
  57.     s11.insert(new Integer(8));
  58.     s11.insert(new Integer(5));
  59.     System.out.println("Set s11 = " + s11);
  60.     Set s14 = s11;

  61.     Set s12 = new Set();
  62.     s12.insert(new Integer(1));
  63.     s12.insert(new Integer(3));
  64.     s12.insert(new Integer(5));
  65.     s12.insert(new Integer(7));
  66.     s12.insert(new Integer(9));
  67.     System.out.println("Set s12 = " + s12);
  68.     Set s13 = s12;

  69.     s11.intersect(s12);
  70.     System.out.println("After s11.intersect(s12), s11 = " + s11);

  71.     System.out.println("Set s13 = " + s13);

  72.     System.out.println("Set s14 = " + s14);

  73.     s13.intersect(s12);
  74.     System.out.println("After s13.intersect(s12), s13 = " + s13);

  75.     s13.intersect(s14);
  76.     System.out.println("After s13.intersect(s14), s13 = " + s13);


  77.     System.out.println("s13.cardinality() = " + s13.cardinality());
复制代码
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

🔗
Simonzz 2015-12-21 22:09:38 | 只看该作者
全局:
简直要调哭了 终于调出来 不过一直报一个warning说Type safety: The method compareTo(Object) belongs to the raw type Comparable. References to generic type Comparable<T> should be parameterized 这个需不需要管啊?
回复

使用道具 举报

全局:
Hw5, match时间复杂度有意思!
更多图片 小图 大图
组图打开中,请稍候......
回复

使用道具 举报

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

本版积分规则

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