一:
using System;
namespace MySort
{
class Program
{
static void Main(string[] args)
{
double[] data = { 52.80, 35.00, 53.40, 26.25, 28.50, 26.80, 28.60, 34.80 };
Sort ms = new Sort();//用于排序的MySort
Console.WriteLine("排序前的数据");
foreach (double item in data)
{
Console.Write(item + " , ");
}
Console.WriteLine("\n排序后的数据:");
ms.SortOne(data); //调用方法
foreach (double item in data)
{
Console.Write(item + ",");
}
MySelect ml = new MySelect();//用于查找的MySelect
ml.Select(data); //调用方法
}
}
public class Sort
{
public void SortOne(double[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
for (int j = i + 1; j < arr.Length; j++)
{
if (arr[j] < arr[i])
{
double temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
}
}
}
public class MySelect
{
public void Select(double[] arr)
{
double min, max;
Console.WriteLine("\n 请输入查找区间:");
min = double.Parse(Console.ReadLine());
max = double.Parse(Console.ReadLine());
Console.WriteLine("查找区间为:" + min + "---" + max);
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] >= min && arr[i] <= max)
{
Console.Write(arr[i] + ",");
}
}
}
}
}