在Main中定义student的结构体,进行年龄从大到小依次排序录入学生信息。(结构体的用法以及冒泡排序)
2024-10-18 22:35:49
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 = ; 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 = ; i <count; i++)
{
for (int j = i+; 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}\n",s.code,s.name,s.old);
}
Console.ReadLine(); }
}
}
最新文章
- 微信支付JSAPI模式及退款CodeIgniter集成篇
- ThinkPHP报错处理
- Qt 按键长按的处理
- 判断线段相交 -- 51nod 1264 线段相交
- 初识io流条件状态
- 《Python基础教程(第二版)》学习笔记 ->; 第九章 魔法方法、属性和迭代器
- C#中委托和事件的区别实例解析
- 关于DJANGO和JAVASCRIPT的时间
- android119 侧滑菜单
- Qapp使用总结
- 高放的c++学习笔记之类
- Node.js log1: ERR can not find module express
- atitit.为什么技术的选择方法java超过.net有前途
- Linux环境进程间通信(一):管道及命名管道
- 解决Chrome动画”卡顿”的办法
- 苹果ATS特性服务器证书配置指南
- rapidPHP 下载并安装
- SpringBoot 统一时区的方案
- FastCGI sent in stderr: ";PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, &#39;&;lt;&#39; not found in
- chmod a+r file:给所有用户添加读的权限
热门文章
- 研:手势与眼动相结合-手势SDK的整合
- C语言 后缀自增的优先级详解
- 获取元素的xpath, 转换xpath为csspath进行jQuery元素获取
- [CareerCup] 8.9 An In-memory File System 内存文件系统
- 【iOS功能实现】之利用UIDocumentInteractionController打开和预览文档
- Chrome扩展开发(Gmail附件管理助手)系列之〇——概述
- 成都普华永道税务开发的offer
- JAVA并发的性能调整
- 项目笔记---Windows Service调用Windows API问题
- 每天一个linux命令(47):traceroute命令