zoukankan      html  css  js  c++  java
  • ArrayList集合排序

    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函数的花括号
        }
    }

  • 相关阅读:
    类型反射出错
    洛阳亲友如相问 咱两还要喝一壶
    为什ipad3卖的不好呢?(爆笑)
    位置相关属性offset(),position(),scrollTop()等
    httpModules 与httpHandler
    IE7,IE8不支持New Date的解决方法
    数据库中字符长度和C#代码中字符长度
    让你的wordpress支持Window live writer
    用Windows Live Writer离线写Wordpress博客详解
    请问在数据库中怎样用模糊查询查找含有通配符的项,比如 like ' ' 我要查找含有“%”的项,怎么查?
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4415459.html
Copyright © 2011-2022 走看看