示例#1
0
        public static Knot <T> ToKnot <T>(this IEnumerable <T> source)
        {
            var result = new Knot <T>(source.First());

            foreach (var item in source.Skip(1))
            {
                result.Add(item);
            }

            return(result);
        }
示例#2
0
        public static Knot <TItem> GetUnique <TItem>(this Knot <TItem> source)
        {
            var result = new Knot <TItem>();

            var current = source.Start;
            var history = new List <TItem>();

            while (current != null)
            {
                if (!history.Contains(current.Data))
                {
                    result.Add(current.Data);
                    history.Add(current.Data);
                }

                current = current.Next;
            }

            return(result.Count() > 0 ? result : null);
        }