Beispiel #1
0
        public static void Run()
        {
            // Declare and instantiate a new generic SortedList class. Person is the type argument.
            SortedList <Person> list = new SortedList <Person>();

            // Create name and age values to initialize Person objects.
            string[] names = { "Franscoise", "Bill", "Li", "Sandra", "Gunnar", "Alok", "Hiroyuki", "Maria", "Alessandro", "Raul" };
            int[]    ages  = { 45, 19, 28, 23, 18, 9, 108, 72, 30, 35 };

            // Populate the list.
            for (int x = 0; x < 10; x++)
            {
                list.AddHead(new Person(names[x], ages[x]));
            }

            // Print out unsorted list.
            foreach (Person p in list)
            {
                Console.WriteLine(p.ToString());
            }
            Console.WriteLine("Done with unsorted list");

            // Sort the list.
            list.BubbleSort();

            // Print out sorted list.
            foreach (Person p in list)
            {
                Console.WriteLine(p.ToString());
            }
            Console.WriteLine("Done with sorted list");
        }
Beispiel #2
0
        public ActionResult RunT()
        {
            StringBuilder       strList = new StringBuilder();
            SortedList <Person> list    = new SortedList <Person>();

            string[] names = new string[]
            {
                "Franscoise",
                "Bill",
                "Li",
                "Sandra",
                "Gunnar",
                "Alok",
                "Hiroyuki",
                "Maria",
                "Alessandro",
                "Raul"
            };
            int[] ages = new int[] { 45, 19, 28, 23, 18, 9, 108, 72, 30, 35 };
            for (int x = 0; x < 10; x++)
            {
                list.AddHead(new Person(names[x], ages[x]));
            }
            foreach (Person p in list)
            {
                strList.Append(p.ToString() + "\n");
            }
            strList.Append("Done with unsorted list");

            list.BubbleSort();

            foreach (Person p in list)
            {
                strList.Append(p.ToString() + "\n");
            }
            strList.Append("Done with sorted list");

            return(StatusCode(StatusCodes.Status200OK, strList.ToString()));
        }