首页 > 编程语言 > 详细

结构体数组排序

时间:2015-04-10 20:11:00      阅读:198      评论:0      收藏:0      [点我收藏+]

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

namespace 结构体冒泡排序
{
    class Program
    {
        struct student
        {
            public string name;
            public int age;
        }
        static void Main(string[] args)
        {
            student[] a = new student[3];
            a[0].name = "约里克";
            a[0].age = 11;
            a[1].name = "掘墓者";
            a[1].age = 13;
            a[2].name = "德玛";
            a[2].age = 12;
            for (int i = 1; i <= a.Length; i++)
            {
                for (int j = 1; j <= a.Length - i; j++)
                {
                    if (a[j - 1].age < a[j].age)
                    {
                        student temp;
                        temp = a[j];
                        a[j] = a[j - 1];
                        a[j - 1] = temp;
                    }
                }
            }
            Console.WriteLine("姓名为" + a[0].name + "年龄为" + a[0].age);
            Console.WriteLine("姓名为" + a[1].name + "年龄为" + a[1].age);
            Console.WriteLine("姓名为" + a[2].name + "年龄为" + a[2].age);
            Console.ReadLine();
        }
    }
}

 

结构体数组排序

原文:http://www.cnblogs.com/lk-kk/p/4415464.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!