Beispiel #1
0
        public static MyStackList <T> filter(MyStackList <T> list, FilterHandler filterhandler)
        {
            var filtered = new MyStackList <T>();

            foreach (var item in list)
            {
                if (list.filterHandler(item))
                {
                    filtered.Push(item);
                }
            }
            return(filtered);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            MyStackList <string> shoppingList = new MyStackList <string>();
            MyStackList <string> removeList   = new MyStackList <string>();

            shoppingList.Push("Bread");
            shoppingList.Push("Butter");
            shoppingList.Push("Tea");
            shoppingList.Push("Coffee");
            shoppingList.Push("Sugar");

            foreach (var item in shoppingList)
            {
                Console.WriteLine(item);
            }
            shoppingList.AddToRemoveList += removeList.Push;


            shoppingList.Pop();
            shoppingList.Pop();


            Console.WriteLine();

            foreach (var item in removeList)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();

            var filteredList = MyStackList <string> .filter(shoppingList, shoppingList.filterHandler);

            foreach (var item in filteredList)
            {
                Console.WriteLine(item);
            }
        }