简体   繁体   English

在java中使用状态模式实现队列

[英]Implementing a queue using state pattern in java

我正在尝试学习状态设计模式,我老师提供的练习之一是实现队列,有人可以帮助我吗?

The state design pattern is of the behavioral family and allows objects to alter their behavior depending on their internal state.状态设计模式属于行为家族,允许对象根据其内部状态改变其行为。

There are numerous examples of the state pattern in the Web, you can check for example this or this .网络上有许多状态模式的例子,你可以查看例如thisthis

For implementing a queue using the state pattern, you have to think what states a queue could have (eg, empty, full, etc) and how the behavior of its actions (eg, enqueue, dequeue, peek, etc.) would change based on the state.为了使用状态模式实现队列,您必须考虑队列可能具有的状态(例如,空、满等)以及其操作的行为(例如,入队、出队、偷看等)将如何基于在状态上。

You could also check this for more info about queue data structures.您还可以查看以获取有关队列数据结构的更多信息。

If you play around a bit and have problems, copy some code and we 'll work on it.如果您玩了一会儿并遇到问题,请复制一些代码,我们将对其进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM