中级农民
- 积分
- 248
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2017-12-6
- 最后登录
- 1970-1-1
|
- /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=52029:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Users/Lim/@inbox/cs61b14/lab/lab4/out/production/lab4 DList1
- ### TESTING insertFront ###
- Empty list is [ ]
- Inserting 9 at front.
- List with 9 is [ 9 ]
- Inserting 8 at front.
- List with 8 and 9 is [ 8 9 ]
- ### TESTING removeFront ###
- List with 1 and 2 is [ 1 2 ]
- Removing front node.
- List with 2 is [ 2 ]
- Removing front node.
- Empty list is [ ]
- Removing front node.
- Empty list is [ ]
- Process finished with exit code 0
复制代码- /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=51938:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Users/Lim/@inbox/cs61b14/lab/lab4/out/production/lab4 DList2
- ### TESTING insertFront ###
- Empty list is [ ]
- Inserting 9 at front.
- List with 9 is [ 9 ]
- Inserting 8 at front.
- List with 8 and 9 is [ 8 9 ]
- ### TESTING removeFront ###
- List with 1 and 2 is [ 1 2 ]
- List with 2 is [ 2 ]
- Empty list is [ ]
- Empty list is [ ]
- Process finished with exit code 0
复制代码
总结下:
(2)Dlist1的remove需要考虑size==1的情况,移除唯一的元素后,head = null, 这时候 head.prev 是不存在的,因为null既不是对象也不是一种类型,它仅是一种特殊的值。同时也必须对tail进行讨论,使得tail = null,不然java可能不能回收这个空间。
(1)Dlist2有了sentinel后可以避免上述的讨论
|
|