예제 #1
0
        public static ISimpleTree <T> ToTree <T>(this IList <Tuple <T, T> > pairs) where T : class
        {
            var top     = pairs.Single(x => x.Item2 == null).Item1;
            var topNode = new SimpleTree <T>(top);

            Add(topNode, pairs);
            return(topNode);
        }
예제 #2
0
        public static ISimpleTree <T> ToSimpleTree <T>(this IDictionary <T, T> pairs) where T : class
        {
            var top     = pairs.Single(x => x.Value == null).Key;
            var topNode = new SimpleTree <T>(top);

            Add(topNode, pairs);
            return(topNode);
        }
예제 #3
0
        private static void Add <T>(SimpleTree <T> node, IDictionary <T, T> pairs) where T : class
        {
            var childrenPairs = pairs.Where(pair => pair.Value == node.Data).ToList <KeyValuePair <T, T> >();

            foreach (var cp in childrenPairs)
            {
                var c = new SimpleTree <T>(cp.Key);
                node.Add(c);
                pairs.Remove(cp);

                Add <T>(c, pairs);
            }
        }
예제 #4
0
        private static void Add <T>(SimpleTree <T> node, IList <Tuple <T, T> > pairs) where T : class
        {
            var childrenPairs = pairs.Where(tuple => tuple.Item2 == node.Data).ToList <Tuple <T, T> >();

            foreach (var cp in childrenPairs)
            {
                var c = new SimpleTree <T>(cp.Item1);
                node.Add(c);
                pairs.Remove(cp);

                Add <T>(c, pairs);
            }
        }