由网友(斜劉海遮住右眼角的淚)分享简介:的用例保持最后n列表访问的网址(其中n是一个固定数)。随着新的网址添加到列表中,旧的URL会自动删除(为了保持在n个元素)Usecase maintain a list of the last n visited URLs (where n is a fix number). As new URLs are add...
的用例保持最后n列表访问的网址(其中n是一个固定数)。随着新的网址添加到列表中,旧的URL会自动删除(为了保持在n个元素)
Usecase maintain a list of the last n visited URLs (where n is a fix number). As new URLs are added to the list, older urls are removed automatically (in order to keep it at n elements)
要求需要的数据结构来按时间排序(应该没有问题,如果它接受一个比较)。
Requirement The data structure needs to be sorted by time (should be no problem if it accepts a Comparator).
推荐答案
在java中有几种实施的队列的。它应该是微不足道的继承或扭曲现有的执行和落实add()方法是这样的:
In java there are several implementation of Queue. It should be trivial to inherit or warp an existing implementation and implement the add() method like this:
boolean add(E e) {
if(q.size()==MAX_SIZE) {
remove();
}
q.add(e)
}
相关推荐
最新文章