高级农民
- 积分
- 1752
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2015-3-18
- 最后登录
- 1970-1-1
|
1 Breaking the System- class SNode {
- private Integer val;
- private SNode prev;
- public SNode(Integer v, SNode p) {
- val = v;
- prev = p;
- }
-
- public SNode(Integer v) {
- this(v, null);
- }
- }
复制代码- class BadIntStack {
- private SNode top;
- public boolean isEmpty() {
- return top == null;
- }
- public void push(Integer num) {
- top = new SNode(num, top);
- }
- public Integer pop() {
- if (top == null) {
- return null;
- }
- Integer ans = top.val;
- top = top.prev;
- return ans;
- }
- public Integer peek() {
- if (top == null) {
- return null;
- }
- return top.val;
- }
- }
复制代码- public class Exploiter1 {
- public static void main(String[] args) {
- BadIntStack bis = new BadIntStack();
- bis.pop();
- }
- }
复制代码- public class Exploiter2 {
- public static void main(String[] args) {
- BadIntStack bis = new BadIntStack();
- bis.push(1);
- bis.top.prev = bis.top;
- while (!bis.isEmpty()) {
- bis.pop();
- }
- }
- }
复制代码 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.
|
|