addFirst:
pride-and-prejudice.txt
Total words: 125901
Total different words: 6530
bst time1: 0.0945035
pride-and-prejudice.txt
Total words: 125901
Total different words: 6530
link time2: 1.778542
Process finished with exit code 0
LinkedListSet改为addLast结果如下:
pride-and-prejudice.txt
Total words: 125901
Total different words: 6530
bst time1: 0.0927352
pride-and-prejudice.txt
Total words: 125901
Total different words: 6530
link time2: 0.3961773
Process finished with exit code 0
虽然链表的时间复杂度为O(n), 单从add操作看addFirst时间复杂度为O(1)。
addLast时间复杂度为O(n),后者反而速度更快。
请问这是为啥?