普林斯顿Algorithms-1.3.1-包、队列、栈的数组实现
Bags, Queues, and Stacks (数组实现)
Several fundamental data types involve collections of objects. Specifically, the set of values is a collection of objects, and the operations revolve around adding, removing, or examining objects in the collection. In this section, we consider three such data types, known as the bag, the queue, and the stack.?
API
They differ in the specification of which object is to be removed or examined next.
泛型:集合类的笼统数据类型的一个关键特性是我们可以用他们存储任意类型的数据。
自动装箱拆箱
可迭代的集合类型
包,先进先出队列,下压栈
包不支持删除,为了收集和遍历而生,适合用于统计
队列来得早走的早,跟排队一样,适合任务调度
栈先来的最后走,浏览器的浏览顺序就是一个栈,点击后退就返回之前的页面
算术表达式求值
Dijkstra双栈算法实现的简单解释器
使用定容数组和扩容数组? 实现集合类(非常重要)
Fixed-capacity stack of strings.?FixedCapacityStackOfString.java?implements a fixed-capacity stack of strings using an array.
Fixed-capacity generic stack.?FixedCapacityStack.java?implements a generic fixed-capacity stack.
Array resizing stack.?ResizingArrayStack.java?implements a generic stack using a?resizing array. With a resizing array, we dynamically adjust the size of the array so that it is both sufficiently large to hold all of the items and not so large as to waste an excessive amount of space. We?double?the size of the array in?push()?if it is full; we?halve?the size of the array in?pop()?if it is less than one-quarter full.
Array resizing queue.?ResizingArrayQueue.java?implements the queue API with a resizing array.
动态数组实现下压栈/队列是一个很重要的算法,它几乎达到了任意集合类数据类型实现的最佳性能:
操作用时和集合大小无关
空间需求不超过集合大小*常数
但动态调整的有一个复制原数组的造作,耗时和size正相关,于是为了更加优化,链表诞生了
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » 普林斯顿Algorithms-1.3.1-包、队列、栈的数组实现