输入个人信息按年龄大小排列

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 结构体
{
    class Program
    {
        struct tongji
        {
            public string xm;
            public string sex;
            public int old;
            public double h;
            public double tz;


           
        }
        static void Main(string[] args)
        {  
            
            Console.Write("请输入人数:");
            int a=int.Parse(Console.ReadLine());
            ArrayList arr=new ArrayList();
            for (int i = 0; i < a; i++)
            {

                tongji s = new tongji();
                Console.WriteLine("正在输入第" + (i + 1) + "个人员信息");
                Console.Write("请输入姓名:");
                s.xm = Console.ReadLine();
                Console.Write("请输入性别:");
                s.sex = Console.ReadLine();
                Console.Write("请输入年龄:");
                s.old = int.Parse(Console.ReadLine());
                Console.Write("请输入身高:");
                s.h = double.Parse(Console.ReadLine());
                Console.Write("请输入体重:");
                s.tz = double.Parse(Console.ReadLine());
                arr.Add(s);
            }

            for (int j = 0; j < a - 1; j++)
            {
                for (int k = j+1; k <a; k++)
                {
                    if (((tongji)arr[j]).old > ((tongji)arr[k]).old)
                    {
                        tongji zhong = (tongji)arr[j];
                        arr[j] = arr[k];
                        arr[k] = zhong;

                    }
                }
            }
            Console.Write("姓名\t性别\t年龄\t身高\t体重\n");
            for (int p = 0; p < a; p++)
            {
                Console.Write(((tongji)arr[p]).xm + "\t" + ((tongji)arr[p]).sex + "\t" + ((tongji)arr[p]).old + "\t" + ((tongji)arr[p]).h + "\t" + ((tongji)arr[p]).tz + "\n");
            }
            Console.ReadLine();

 

posted @ 2015-06-19 10:08  蓝瑟黄昏  阅读(225)  评论(0编辑  收藏  举报