惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
博客园 - 聂微东
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
博客园 - 司徒正美
爱范儿
爱范儿
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
博客园 - 【当耐特】
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
人人都是产品经理
人人都是产品经理
V
V2EX

博客园 - cjfwu

设计模式学习4-Bridge模式 设计模式学习3-Strategy模式 设计模式学习2-Adapter模式 设计模式学习1-Facade模式 设备控制(反馈处理) 通过System.IO.Packaging实现打包和解包 将目录添加环境变量 设备控制之矩阵状态显示 windows shell 编程3(函数解释) windows shell 编程2(浏览文件夹) windows shell 编程1(概念) 不同命名空间下名称和结构相同的类相互序列化与反序列化 通过SvcUtil.exe生成客户端代码和配置 在“添加引用”对话框中显示需要的Assembly 只运行一个实例 SVN操作 托盘操作 获得树节点的高度 枚举的操作
分组
cjfwu · 2008-12-05 · via 博客园 - cjfwu

    class GroupTest {
        static void Main(string[] args) {
            List<int> src = new List<int> { 1, 5, 11, 22, 4, 3 };

            List<List<int>> gs = Split<int>(src, (current, next) => { return (current < 10 && next < 10); });
            //List<List<int>> gs = Split<int>(src, (current, next) => { return (current < 10 && next < 10) || (current >= 10 && next >= 10); });

            foreach (var each in gs) {
                List<string> t = new List<string>();
                each.ForEach(e => t.Add(e.ToString()));
                Console.WriteLine(string.Join(" ", t.ToArray()));
            }

            Console.WriteLine("== End ==");
            Console.ReadKey();
        }

        private static List<List<T>> Split<T>(List<T> src, Condition<T> condition) {
            List<List<T>> result = new List<List<T>>();

            List<T> current = new List<T>();
            for (int i = 0; i < src.Count; ++i) {
                T cur = src[i];
                T next = default(T);
                if (i < src.Count - 1) { next = src[i + 1]; }

                current.Add(cur);
                if (src.Count == i + 1 || !condition(cur, next)) {
                    result.Add(current);
                    current = new List<T>();
                }
            }

            return result;
        }
    }

    delegate bool Condition<T>(T current, T next);