Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("输入一个泛型链表");
            Console.WriteLine("输入链表长度N");
            int N;

            N = Int32.Parse(Console.ReadLine());
            string choice;

            Console.WriteLine("输入链表类型:1、整型;2、字符串型");
            choice = Console.ReadLine();
            switch (choice)
            {
            case "1":
                GenericList <int> intList = new GenericList <int>();
                for (int i = 1; i <= N; i++)
                {
                    Console.WriteLine("输入第" + i + "个元素");
                    int k = Int32.Parse(Console.ReadLine());
                    intList.Add(k);
                }
                Action <int> action1 = (m => Console.WriteLine(m));
                intList.ForEach(intList.Head, action1);
                break;

            case "2":
                GenericList <string> strList = new GenericList <string>();
                for (int i = 1; i <= N; i++)
                {
                    Console.WriteLine("输入第" + i + "个元素");
                    string k = Console.ReadLine();
                    strList.Add(k);
                }
                Action <string> action2 = (m => Console.WriteLine(m));
                strList.ForEach(strList.Head, action2);
                break;

            default:
                Console.WriteLine("无该选项");
                break;
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            GenericList <int> list = new GenericList <int>();

            for (int i = 1; i <= 10; i++)
            {
                list.Add(i);
            }
            int max = list.Head.Data;
            int min = list.Head.Data;
            int sum = 0;

            list.ForEach((x) =>
            {
                Console.WriteLine(x);
                max  = Math.Max(max, x);
                min  = Math.Min(min, x);
                sum += x;
            });
            Console.WriteLine($"\nMax: {max}\nMin: {min}\nSum: {sum}");
        }