主类:

    public class InfiniteList<T> : IEnumerable<T> {
public List<T> SourceList { get; }
int start { get; }
public int Step { get; set; } = 1; public InfiniteList(IEnumerable<T> source) : this(0, source) {
} public InfiniteList(int start, IEnumerable<T> source) {
this.start = Math.Max(Math.Min(start, source.Count()), -1);
SourceList = new List<T>(source);
} public InfiniteEnumerator<T> GetInfiniteEnumerator() {
return new InfiniteEnumerator<T>(this, start);
} public IEnumerator<T> GetEnumerator() {
return GetInfiniteEnumerator();
} IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
}

迭代类:

    public class InfiniteEnumerator<T> : IEnumerator<T> {
InfiniteList<T> list;
int start; public int Index { get; set; }
public int Step { get; set; }
public InfiniteEnumerator(InfiniteList<T> source, int start) {
list = source;
Index = start - source.Step;
this.start = start;
Step = source.Step;
} public T Current {
get { return list.SourceList[Index]; }
} object IEnumerator.Current {
get { return Current; }
} public void Dispose() {
} public bool MoveNext() {
if (list.SourceList.Count == 0) {
return false;
}
if (Step == 0) {
return false;
}
Index += Step;
while (Index > list.SourceList.Count - 1) {
Index -= list.SourceList.Count;
}
while (Index < 0) {
Index += list.SourceList.Count;
} return true;
} public void Reset() {
Index = start;
}
}

加强型无穷集合:InfiniteList<T>,可指定遍历方向和偏移量,只要集合有元素并且偏移量不为 0,将永远遍历下去。的更多相关文章

  1. not(expr|ele|fn)从匹配元素的集合中删除与指定表达式匹配的元素

    not(expr|ele|fn) 概述 从匹配元素的集合中删除与指定表达式匹配的元素   参数 exprStringV1.0 一个选择器字符串.深圳dd马达 elementDOMElementV1.0 ...

  2. 解决在jsp页面中使用jstl无法遍历request域中list集合的问题

    解决在jsp页面中使用jstl无法遍历request域中list集合的问题 1. 前言 ​ 最近在写一个很简单的Javaweb项目,里面需要将request域中的list集合加载到jsp页面,我使用e ...

  3. ArrayList集合实现RandomAccess接口有何作用?为何LinkedList集合却没实现这接口

    详见:https://blog.csdn.net/weixin_39148512/article/details/79234817 众所周知,在List集合中,我们经常会用到ArrayList以及Li ...

  4. 005-guava 集合-集合工具类-java.util.Collections中未包含的集合工具[Maps,Lists,Sets],Iterables、Multisets、Multimaps、Tables

    一.概述 工具类与特定集合接口的对应关系归纳如下: 集合接口 属于JDK还是Guava 对应的Guava工具类 Collection JDK Collections2:不要和java.util.Col ...

  5. Day_11【集合】扩展案例2_使用普通for循环获取集合中索引为3的元素并打印,统计集合中包含字符串"def"的数量,删除集合中的所有字符串",将集合中每个元素中的小写字母变成大写字母def",

    分析以下需求,并用代码实现 1.定义ArrayList集合,存入多个字符串"abc" "def" "efg" "def" ...

  6. C# List 集合 交集、并集、差集、去重, 对象集合、 对象、引用类型、交并差补、List<T>

    关键词:C#  List 集合 交集.并集.差集.去重, 对象集合. 对象.引用类型.交并差.List<T> 有时候看官网文档是最高效的学习方式! 一.简单集合 Intersect 交集, ...

  7. UVA12096 集合栈计算机(map和vector实现双射关系+集合的交并运算的STL)

    题目大意: 对于一个以集合为元素的栈,初始时栈为空. 输入的命令有如下几种: PUSH:将空集{}压栈 DUP:将栈顶元素复制一份压入栈中 UNION:先进行两次弹栈,将获得的集合A和B取并集,将结果 ...

  8. 指针数组的初始化和遍历,并且通过for循环方式、函数传参方式进行指针数组的遍历

    /************************************************************************* > File Name: message.c ...

  9. jQuery遍历对象、数组、集合实例

    1.jquery 遍历对象 复制代码代码如下:   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ...

随机推荐

  1. Python基础、文件处理

    一.概述 Python中操作文件是通过file对象来处理的,步骤: 指定文件的路径.操作的模式 对文件进行操作,读或写操作 关闭文件对象 f = open( '文件路径','访问模式') # 打开文件 ...

  2. [Android Tips] 15. Enforcing spaces in string resources

    解决方案 使用双引号括起来 使用空格符的 unicode 编码 \u0200 ref Enforcing spaces in string resources How to put space cha ...

  3. 小Q系列之 最佳裁判

    这个题需要注意一些数据条件 尤其是一些输入数据条件 #include<algorithm> #include<stdio.h> #include<math.h> u ...

  4. Leetcode: Minimum Number of Arrows to Burst Balloons

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  5. .NET学习记录1

    .NET 可以干什么呢? 1.桌面应用程序 (WinForm ) 2.internet 应用程序(asp.net) 3.手机应用开发(wp7)好像现在C#也能开发android应用了 现在主要有两个方 ...

  6. ligerui_ligerTree_004_对"ligerTree"节点操作

    ligerTree节点操作: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图: 代码: json.txt: [ { text ...

  7. [firefox]在Debian7及其衍生版下安装firefox

    Easy way to install Firefox browser on Debian 7 wheezy Debian by default comes with Iceweasel web br ...

  8. 最快速的Android开发环境搭建ADT-Bundle及Hello World

    ADT-Bundle for Windows 是由Google Android官方提供的集成式IDE,已经包含了Eclipse,你无需再去下载Eclipse,并且里面已集成了插件,它解决了大部分新手通 ...

  9. javaWeb 使用 filter 处理全站乱码问题

    1. web.xml文件中的配置 <filter> <filter-name>CharacterEncodingFilter</filter-name> <f ...

  10. 锁表 for update

    select for update 是为了在查询时,避免其他用户以该表进行插入,修改或删除等操作,造成表的不一致性. 举几个例子:select * from t for update 会等待行锁释放之 ...