📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
查看: 1824| 回复: 1
跳转到指定楼层
上一主题 下一主题
收起左侧

[CS 61B Spring 2015] Discussion 7

全局:
公开课
学校名称: UC Berkeley
Unit号: 7
开课时间: 2015-01-01
课程全名: CS 61B: Data Structures
平台: 其他

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
发现没有人发这周的帖子……这个discussion的内容是
  • Breaking the System
  • Immutable Rocks
  • Design a Parking Lot


上一篇:也吐槽udacity课程质量下降
下一篇:[CS 61B Spring 2015] Discussion 8
🔗
 楼主| HNAKXR 2016-2-15 15:58:49 | 只看该作者
全局:
1 Breaking the System
  1. class SNode {
  2.         private Integer val;
  3.         private SNode prev;

  4.         public SNode(Integer v, SNode p) {
  5.                 val = v;
  6.                 prev = p;
  7.         }
  8.         
  9.         public SNode(Integer v) {
  10.                 this(v, null);
  11.         }
  12. }
复制代码
  1. class BadIntStack {
  2.         private SNode top;

  3.         public boolean isEmpty() {
  4.                 return top == null;
  5.         }

  6.         public void push(Integer num) {
  7.                 top = new SNode(num, top);
  8.         }

  9.         public Integer pop() {
  10.                 if (top == null) {
  11.                         return null;
  12.                 }
  13.                 Integer ans = top.val;
  14.                 top = top.prev;
  15.                 return ans;
  16.         }

  17.         public Integer peek() {
  18.                 if (top == null) {
  19.                         return null;
  20.                 }
  21.                 return top.val;
  22.         }
  23. }
复制代码
  1. public class Exploiter1 {
  2.         public static void main(String[] args) {
  3.                 BadIntStack bis = new BadIntStack();
  4.                 bis.pop();
  5.         }
  6. }
复制代码
  1. public class Exploiter2 {
  2.         public static void main(String[] args) {
  3.                 BadIntStack bis = new BadIntStack();
  4.                 bis.push(1);
  5.                 bis.top.prev = bis.top;
  6.                 while (!bis.isEmpty()) {
  7.                         bis.pop();
  8.                 }
  9.         }
  10. }
复制代码
2 Immutable Rocks
No
Yes
No
No
No
No

3 Design a Parking Lot
Three classes under the parkinglot package:
  • ParkingLot: Control the parking lot in total. Assign the closest permitted spaces to coming cars. Sort all parking space available by distance.
  • Space: The space for parking, which has three different types. Check type of space and car to verify whether parking is allowed.
  • Car: Just a car with three types.

评分

参与人数 1大米 +20 收起 理由
zzwcsong + 20

查看全部评分

回复

使用道具 举报

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

本版积分规则

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