对数据进行排序,最大的和最小的穿插

 List<int> list = new List<int>();
            list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            int len = list.Count - 1;
            list.Sort();
            list.ForEach(Console.WriteLine);
            List<int> listLast = new List<int>();
            for (int i = len-1; i >=0; i--)
            {
                if (i % 2 == 0)
                {
                    listLast.Add(list.Max());
                    list.Remove(list.Max());
                    continue;
                }
                listLast.Add(list.Min());
                list.Remove(list.Min());
            }
            listLast.ForEach(Console.WriteLine);
            for (int i = len - 1; i >= 0; i--)
            {
                if (i >= (len - 1) / 2)
                    break;
                if (i % 2 == 0)
                    continue;
                int temp = list[i];
                list[i] = list[len - 1];
                list[len - 1] = temp;
            }
            Console.ReadKey();

posted @ 2017-04-20 18:39  荣码一生  阅读(290)  评论(0编辑  收藏  举报