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

推荐订阅源

Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
C
Check Point Blog
I
InfoQ
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
月光博客
月光博客
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
博客园 - Franky
博客园_首页
罗磊的独立博客
量子位
美团技术团队
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
博客园 - 叶小钗
aimingoo的专栏
aimingoo的专栏

博客园 - 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);