Beispiel #1
0
        public IEnumerable <CategoryComponent> Parents()
        {
            CategoryComponent result = this;

            while (result.Parent != null)
            {
                result = result.Parent;
                yield return(result);
            }
        }
        public override IEnumerable <CategoryComponent> WalkTreeDepthFirst()
        {
            // http://en.wikipedia.org/wiki/Depth-first_search
            HashSet <CategoryComponent> seenIt  = new HashSet <CategoryComponent>();
            Stack <CategoryComponent>   toVisit = new Stack <CategoryComponent>();

            toVisit.Push(this);

            while (toVisit.Any())
            {
                CategoryComponent item = toVisit.Pop();
                if (!seenIt.Contains(item))
                {
                    seenIt.Add(item);
                    foreach (CategoryComponent child in _children.ToArray().Reverse())
                    {
                        toVisit.Push(child);
                    }
                    yield return(item);
                }
            }
        }
        public override IEnumerable <CategoryComponent> WalkTreeBreadthFirst()
        {
            //http://en.wikipedia.org/wiki/Breadth-first_search
            HashSet <CategoryComponent> seenIt  = new HashSet <CategoryComponent>();
            Queue <CategoryComponent>   toVisit = new Queue <CategoryComponent>();

            toVisit.Enqueue(this);

            while (toVisit.Any())
            {
                CategoryComponent item = toVisit.Dequeue();
                if (!seenIt.Contains(item))
                {
                    seenIt.Add(item);
                    foreach (CategoryComponent child in _children)
                    {
                        toVisit.Enqueue(child);
                    }
                    yield return(item);
                }
            }
        }
 public override void Remove(CategoryComponent component)
 {
     _children.Remove(component);
 }
 public override void Add(CategoryComponent component)
 {
     _children.Add(component);
 }
Beispiel #6
0
 public abstract void Remove(CategoryComponent c);
Beispiel #7
0
 public abstract void Add(CategoryComponent c);
 public override void Remove(CategoryComponent c)
 {
     throw new NotImplementedException();
 }