1. stack
push入,pop出,先入后出(尾入尾出),像一个杯子
- Linked-list implementation.
・Every operation takes constant time in the worst case.
・Uses extra time and space to deal with the links. - Resizing-array implementation.
・Every operation takes constant amortized time.
・Less wasted space.
根据不同的情况需要不同的实现方法,操作数组虽然花费的时间更短空间也更小,但是当大量数据包涌入不希望造成系统突然卡住造成数据丢失时,就不能采用数组。如果不在乎这个,只在意总时间,可以采用数组。
stack的应用举例:方法调用、递归方法、数学表达式的计算
2. Queue
enqueue入,dequeue出,先入先出(尾入头出),像排队
3. Bag
主要的作用就是加入东西,能够获得size和以任意顺序遍历,就像一个包。
这一节还讲了迭代器、泛型,这些都是61B讲的更好更细致一些。