如题:输入5个人的成绩 然后自定义方法排序。。
解决方案 »
- float类型经乘法运算后强制转换成short类型数值不准确(未溢出),求大神解惑
- 请问xml文件的节点名中出现&而读取错误怎么办啊?
- C#中form窗体类继承的子类中删除基类按钮的问题
- 如何从DataGrid1里的某个超级链接列向DataGrid2传递参数,在DataGrid2里显示详细信息?
- 【求助】求一正则表达式
- 关于窗口继承的超级问题
- 欢迎大家讨论,vs.net中cs模式和bs模式的主要区别 顺便放分…………~~
- DataGrid 里面每条记录的字体大小怎么改?
- 一个解析xml的奇怪问题
- 在WINFORM 中的DATAGRID 中,如何在编辑时显示下拉列表框 急
- 窗体如何在两个工程间复制
- CheckedListBox打勾、取消打勾触发哪个事件?
Array.Sort(你的数组);
using System.Collections.Generic;
using System.Text;namespace Text
{
class Program
{
static void Main(string[] args)
{
int[] count = new int[5]; // 需要排序的数组
int i, j; // 循环变量
int temp; // 临时变量 // 读入数组
Console.WriteLine("请输入5个数:");
for (i = 0; i < 5; i++)
{
Console.WriteLine("输入第{0}个数:",i+1);
count[i] = int.Parse(Console.ReadLine()); // 类型转换 }
// 开始排序 -----------冒泡排序
for (i = 0; i < count.Length-1; i++) // 控制比较多少轮
{
// 将最大的元素交换到最后
for (j = 0; j < count.Length-1-i; j++)
{
if(count[j] > count[j+1])
{
// 交换元素
temp = count[j];
count[j] = count[j + 1];
count[j + 1] = temp;
}
}
}
// 排序后输出
Console.WriteLine("排序后:");
for (i = 0; i < count.Length; i++)
{
Console.WriteLine("{0}\t",count[i]);
}
Console.ReadLine();
}
}
}
{
int[] count = new int[5]; // 需要排序的数组
Console.WriteLine("请输入5个数:");
for (int i = 0; i < 5; i++)
{
Console.WriteLine("输入第{0}个数:", i + 1);
count[i] = int.Parse(Console.ReadLine()); // 类型转换 }
// 开始排序 -----------冒泡排序方法
NewMethod1(ref count);
// 排序后输出
for (int i = 0; i < count.Length; i++)
{
Console.WriteLine("{0}\t", count[i]);
}
}
private static void NewMethod1(ref int[] count)
{
int temp;
for (int i = 0; i < count.Length - 1; i++) // 控制比较多少轮
{
// 将最大的元素交换到最后
for (int j = 0; j < count.Length - 1 - i; j++)
{
if (count[j] > count[j + 1])
{
// 交换元素
temp = count[j];
count[j] = count[j + 1];
count[j + 1] = temp;
}
}
}
}
class MyArray{
public string mySort(string[] oldStr){
string[] resultStr=String.Empty;
// 开始排序 ----laoas兄的代码-------冒泡排序
return resultStr;
}
}MyArray arrSort = ne MyArray();
arrSort.mySort(需要排序的字符串数组);
初学 还不太会用,