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

  • 相关阅读:
    kafka window环境搭建
    oracle 日期格式化和数据去重
    angular $http服务详解
    Spring框架之beans源码完全解析
    计算机经典书籍100本分享
    Thinking in Java 4th(Java编程思想第四版)文档、源码、习题答案
    Spring框架之事务源码完全解析
    TCP/IP网络协议层对应的RFC文档
    Spring源码深度解析之事务
    Spring框架之websocket源码完全解析
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4415459.html
Copyright © 2011-2022 走看看