zoukankan      html  css  js  c++  java
  • 在Main中定义student的结构体,进行年龄从大到小依次排序录入学生信息。(结构体的用法以及冒泡排序)

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    
    
    namespace c编程练习题
    {
       
        class Program
        {
           public  struct student               //结构体的用法。
           {
              public int code;
              public string name;
              public int old;
             }
     static void Main(string[] args)
            {
                    Console.WriteLine("请输入学生的人数");
                    int count = int.Parse(Console.ReadLine());
                    ArrayList arr=new ArrayList();
                    for (int i = 0; i < count; i++)
                    {
    
                        student s = new student();
                        Console.WriteLine("学号:");
                        s.code = int.Parse(Console.ReadLine());
                        Console.WriteLine("姓名:");
                        s.name = Console.ReadLine();
                        Console.WriteLine("年龄:");
                        s.old = int.Parse(Console.ReadLine());
                        arr.Add(s);
                    }
                    for (int i = 0; i <count; i++)
                    {
                        for (int j = i+1; j < count ; j++)
                        {
                            if (((student)arr[i]).old<((student)arr[j]).old)
                            {
                                student temp = (student)arr[i];
                               arr[i] = arr[j];
                               arr[j] = temp;
                            }
                        }
                    }
                    Console.WriteLine("学号     姓名      年龄    从大到小依次排列");
                    foreach (student s in arr)
                    {
                        Console.Write("{0}     {1}      {2}
    ",s.code,s.name,s.old);
                    }
                    Console.ReadLine();
    
            
            }
        }
    }
  • 相关阅读:
    sql知识
    铁道部新客票系统设计(三)
    PYTHON压平嵌套列表
    快速升级App支持iOS6及iPhone5的4寸屏幕
    TreeListView
    杭州ADC技术嘉年华两日总结SOA,去C
    .NET(C#): Task.Unwrap扩展方法和async Lambda
    关于分布式系统的数据一致性问题
    wcf 随笔1
    Linux进程基础
  • 原文地址:https://www.cnblogs.com/kangshuai/p/4576453.html
Copyright © 2011-2022 走看看