コード例 #1
0
ファイル: IIterator.cs プロジェクト: barld/MonoForms
        internal static IEnumerator <T> ToIEnumerator <T>(this IIterator <T> iterator)
        {
            var value = iterator.GetNext();

            while (value is Some <T> )
            {
                yield return((value as Some <T>).Value);

                value = iterator.GetNext();
            }
        }
コード例 #2
0
 public static void PrintMenu(this IIterator iterator)
 {
     while (iterator.HasNext())
     {
         Console.WriteLine(iterator.GetNext());
     }
 }
コード例 #3
0
 private void IterateMenu(IIterator iterator)
 {
     while (iterator.HasNext())
     {
         Console.WriteLine(iterator.GetNext().ToString());
     }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: XpellCZ/ZPR
        static void Main(string[] args)
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            for (int i = 0; i < 10; i++)
            {
                list.Add(i);
            }


            IIterator <int> iterator = list.GetIterator();

            while (iterator.HasNext())
            {
                Console.WriteLine(iterator.GetNext());
            }

            Console.WriteLine("----");

            foreach (int item in list)
            {
                Console.WriteLine(item);
            }


            Console.ReadLine();
        }
コード例 #5
0
 public void Send(IIterator iterator, string message)
 {
     while (iterator.HasMore())
     {
         _profile = iterator.GetNext();
         SendMail(_profile.GetEmail, "Hello World");
     }
 }
コード例 #6
0
        public void ListMenus()
        {
            IIterator iterator = _allMenus.GetIterator();

            while (iterator.HasNext())
            {
                iterator.GetNext().Print();
            }
        }
コード例 #7
0
ファイル: Menu.cs プロジェクト: PlumpMath/DesignPatterns-391
 public override void Print()
 {
     Console.WriteLine("\n\nThis is {0} menu. {1}\n---------------------------", GetName(), GetDescription());
     foreach (var menuComponent in _components)
     {
         menuComponent.Print();
         IIterator iterator = menuComponent.GetIterator();
         while (iterator.HasNext())
         {
             iterator.GetNext().Print();
         }
     }
 }
コード例 #8
0
        public void ListVegetarianMenu()
        {
            IIterator iterator = _allMenus.GetIterator();

            while (iterator.HasNext())
            {
                MenuComponent component = iterator.GetNext();
                if (component.IsLeaf() && component.IsVegetarian())
                {
                    component.Print();
                }
            }
        }
コード例 #9
0
        public override int CountRoutes(City city)
        {
            IIterator iterator = base.database.GetRoutesFrom(city);
            int       count    = 0;

            while (iterator.HasNext())
            {
                Route r = iterator.GetNext();
                if (r.To.Population >= this.minPopulation)
                {
                    count++;
                }
            }
            return(count);
        }
コード例 #10
0
        public override int CountRoutes(City city)
        {
            IIterator iterator = base.database.GetRoutesFrom(city);
            int       count    = 0;

            while (iterator.HasNext())
            {
                Route r = iterator.GetNext();
                if (r.To.HasRestaurant)
                {
                    count++;
                }
            }
            return(count);
        }
コード例 #11
0
        public IEnumerable <Route> Solve(IGraphDatabase graph, City from, City to)
        {
            Dictionary <City, Route> routes = new Dictionary <City, Route>();

            routes[from] = null;
            Stack <City> stack = new Stack <City>();

            stack.Push(from);
            do
            {
                City city = stack.Pop();
                IIterator <Route> iterator = graph.GetRoutesFrom(city);
                while (!iterator.IsDone())
                {
                    Route route = iterator.GetNext();
                    if (route == null)
                    {
                        continue;
                    }

                    if (routes.ContainsKey(route.To))
                    {
                        continue;
                    }
                    routes[route.To] = route;
                    if (route.To == to)
                    {
                        break;
                    }
                    stack.Push(route.To);
                }
            } while (stack.Count > 0);
            if (!routes.ContainsKey(to))
            {
                return(null);
            }
            List <Route> result = new List <Route>();

            for (Route route = routes[to]; route != null; route = routes[route.From])
            {
                result.Add(route);
            }
            result.Reverse();
            return(result);
        }
コード例 #12
0
        public IEnumerable <Route> Solve(IGraphDatabase graph, City from, City to)
        {
            Dictionary <City, Route> routes = new Dictionary <City, Route>();

            routes[from] = null;
            Queue <City> queue = new Queue <City>();

            queue.Enqueue(from);
            do
            {
                City city = queue.Dequeue();

                /*
                 * For each outgoing route from city...
                 */
                IIterator iterator = graph.GetRoutesFrom(city);
                while (iterator.HasNext())
                {
                    Route route = iterator.GetNext(); /* Change to current Route*/
                    if (routes.ContainsKey(route.To))
                    {
                        continue;
                    }
                    routes[route.To] = route;
                    if (route.To == to)
                    {
                        break;
                    }
                    queue.Enqueue(route.To);
                }
            } while (queue.Count > 0);
            if (!routes.ContainsKey(to))
            {
                return(null);
            }
            List <Route> result = new List <Route>();

            for (Route route = routes[to]; route != null; route = routes[route.From])
            {
                result.Add(route);
            }
            result.Reverse();
            return(result);
        }
コード例 #13
0
        public int GetEmptyId(IIterator playerIterator)
        {
            var players = new List <Player>();

            while (playerIterator.HasNext())
            {
                players.Add(playerIterator.GetNext());
            }

            var tempId = 3;

            foreach (var player in players.OrderByDescending(p => p.Id))
            {
                if (player.Id != tempId)
                {
                    return(tempId);
                }

                tempId--;
            }

            return(-1);
        }
コード例 #14
0
        static void Main(string[] args)
        {
            ArrayCollection arrayCollection = new ArrayCollection(5);

            for (int i = 0; i < arrayCollection.Length(); i++)
            {
                arrayCollection[i] = new Item($"Item {i}");
            }

            IIterator arrayIterator = arrayCollection.GetIterator();

            Console.WriteLine("Array collection iteration:");

            while (arrayIterator.HasMore())
            {
                Console.WriteLine(arrayIterator.GetNext().Name);
            }

            Console.WriteLine();

            DictionaryCollection dictionaryCollection = new DictionaryCollection();

            for (int i = 0; i < 10; i++)
            {
                dictionaryCollection[$"Key {i}"] = new Item($"Item {i}");
            }

            IIterator dictionaryIterator = dictionaryCollection.GetIterator();

            Console.WriteLine("Dictionary collection iteration:");

            while (dictionaryIterator.HasMore())
            {
                Console.WriteLine(dictionaryIterator.GetNext().Name);
            }
        }
コード例 #15
0
 public override Route this[City city, int index]
 {
     get
     {
         if (index >= 0 && index < CountRoutes(city))
         {
             IIterator iterator = base.database.GetRoutesFrom(city);
             int       count    = -1;
             while (iterator.HasNext())
             {
                 Route r = iterator.GetNext();
                 if (r.To.Population >= this.minPopulation)
                 {
                     count++;
                     if (count == index)
                     {
                         return(r);
                     }
                 }
             }
         }
         return(null);
     }
 }
コード例 #16
0
        public IEnumerable <Route> Solve(IGraphDatabase graph, City from, City to)
        {
            Dictionary <City, (double dist, Route last)> distances = new Dictionary <City, (double dist, Route last)>();
            HashSet <City> visitedCitites = new HashSet <City>();

            distances[from] = (0, null);
            City minCity = from;

            while (minCity != to)
            {
                /*
                 * For each outgoing route from minCity...
                 */
                IIterator iterator = graph.GetRoutesFrom(minCity);
                while (iterator.HasNext())
                {
                    Route route = iterator.GetNext();                     /* Change to current Route*/
                    if (visitedCitites.Contains(route.To))
                    {
                        continue;
                    }
                    double dist = distances[minCity].dist + OptimizingValueFunc(route);
                    if (!distances.ContainsKey(route.To))
                    {
                        distances[route.To] = (dist, route);
                    }
                    else
                    {
                        if (dist < distances[route.To].dist)
                        {
                            distances[route.To] = (dist, route);
                        }
                    }
                }
                visitedCitites.Add(minCity);
                minCity = null;
                foreach (var(city, (dist, route)) in distances)
                {
                    if (visitedCitites.Contains(city))
                    {
                        continue;
                    }
                    if (minCity == null || dist < distances[city].dist)
                    {
                        minCity = city;
                    }
                }
                if (minCity == null)
                {
                    return(null);
                }
            }
            List <Route> result = new List <Route>();

            for (Route route = distances[to].last; route != null; route = distances[route.From].last)
            {
                result.Add(route);
            }
            result.Reverse();
            return(result);
        }