先是TestDList的输出结果:- Now we are testing DList.
- Here is a list after insertBack 6, 9, 12: [ 6 9 12 ]
- Here is the same list after insertBack(15) and insertFront(3): [ 3 6 9 12 15 ]
- front() should be 3. It is: 3
- front's next should be 6. It is: 6
- front's next's prev should be 3. It is: 3
- After remove the front, the front() should be 6. It is: 6
- After insertBefore() and insertAfter(), The first 3 nodes should be 5,6,8. The list is: [ 5 6 8 9 12 15 ]
- Here is a list after construction: [ ]
- isEmpty() should be true. It is: true
- length() should be 0. It is: 0
- Here is a list after insertFront(3) to an empty list: [ 3 ]
- Here is a list after insertBack(5) on an empty list: [ 5 ]
- Here is a list after insertFront 3, 2, 1: [ 1 2 3 ]
- isEmpty() should be false. It is: false
- length() should be 3. It is: 3
- Here is the same list after insertBack(4): [ 1 2 3 4 ]
- Here is a list after insertBack 6, 7: [ 6 7 ]
- isEmpty() should be false. It is: false
- length() should be 2. It is: 2
- Here is the same list after insertFront(5): [ 5 6 7 ]
复制代码 再是TestLockDlist的输出结果:- Now we are testing LockDList.
- Here is a list after insertBack 6, 9, 12: [ 6 9 12 ]
- Here is the same list after insertBack(15) and insertFront(3): [ 3 6 9 12 15 ]
- front() should be 3. It is: 3
- front's next should be 6. It is: 6
- front's next's prev should be 3. It is: 3
- We lockNode front()= 3
- After remove the locked front, the front() should still be 3. It is: 3
- After remove the back, the back() should be 12. It is: 12
- After insertBefore(3) and insertAfter(3), The first 3 nodes should be 5,3,8. The list is: [ 5 3 8 6 9 12 ]
- Here is a list after construction: [ ]
- isEmpty() should be true. It is: true
- length() should be 0. It is: 0
- Here is a list after insertFront(3) to an empty list: [ 3 ]
- Here is a list after insertBack(5) on an empty list: [ 5 ]
- Here is a list after insertFront 3, 2, 1: [ 1 2 3 ]
- isEmpty() should be false. It is: false
- length() should be 3. It is: 3
- Here is the same list after insertBack(4): [ 1 2 3 4 ]
- Here is a list after insertBack 6, 7: [ 6 7 ]
- isEmpty() should be false. It is: false
- length() should be 2. It is: 2
- Here is the same list after insertFront(5): [ 5 6 7 ]
复制代码 PS.问题求解答~
做第一部分的时候,一直出现空DList的插入报错,后来把DList Constructor中的
head= newNode(null,head,head); 改成 head= newNode(null,null,null); head.prev= head.next = head; 就没问题了,不理解为什么>_<
|