码迷,mamicode.com
首页 > 编程语言 > 详细

ArrayList集合排序

时间:2015-04-10 20:05:15      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace ArrayList集合排序
{
    class Program
    {
        struct Player
        {
            public string name;
            public int mark;
          
        }
        static void Main(string[] args)
        {
            ArrayList al = new ArrayList();
            Player a = new Player();
            Console.WriteLine("请输入你们班的人数");
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("请输入姓名:");
                a.name = Console.ReadLine();
                Console.WriteLine("请输入成绩");
                a.mark = Convert.ToInt32(Console.ReadLine());
                al.Add(a); 
            }
            for (int i = 1; i < al.Count; i++)
            {
                for (int j = 1; j <= al.Count-i; j++)
                {
                    if(((Player)al[j]).mark<((Player)al[j-1]).mark)
                    {
                        Player temp ;
                        temp = (Player)al[j -1];
                        al[j -1] = (Player)al[j];
                        al[j] = temp;
                    }
                }
            }
            for (int i = 0; i < al.Count; i++)
            {
                Console.WriteLine(((Player)al[i]).name+((Player)al[i]).mark);
            }
          
            Console.ReadLine();
        } //static函数的花括号
    }
}

ArrayList集合排序

标签:

原文地址:http://www.cnblogs.com/lk-kk/p/4415459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!