//判定数组是否有序
//总的程序代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
int index = 0;
bool result;
Console.WriteLine("请输入一组数,中间用空格隔开:");
string input = Console.ReadLine();
string[] num=input.Split(new string[]{" "},StringSplitOptions.None);
int[] nums=new int[num.Count<string>()];
while(index<num.Count<string>())
{
nums[index] = Int32.Parse(num[index]);
index++;
}
Fun(nums,out result);
if (result)
{
Console.WriteLine("这组数已经排好序");
}
else
Console.WriteLine("这组数未排序");
Console.ReadKey();
}
public static void Fun(int[] array,out bool result)
{
result = true;
if(array[0]<array[1])
{
for (int i = 1; i < array.Length;i++ )
{
if (array[i - 1] < array[i])
continue;
else
{
result = false;
}
}
}
else
{
for (int i = 1; i < array.Length; i++)
{
if (array[i - 1] >= array[i])
continue;
else
{
result = false;
}
}
}
}
}
}
//执行的结果如下: