运行后排序不完全,而且不能完全的输出排序后的结果
using System;
using System.Collections.Generic;
using System.Text;
namespace learn_c_sharp
{
class Program
{
static void Main(string[] args)
{
const int size = 50;
Console.WriteLine("How many strings will be sort?\nPlease input the num:");
int num=Convert.ToUInt16(Console.ReadLine());
string[] strarray = new string[size];//定义字符串数组
sort(strarray, num);
}
static void sort(string[] str,int num)
{
Console.WriteLine("Please input the string:\n");//输入数据
for (int i = 0; i < num; i++)
{
Console.WriteLine("Input the No.{0}",i+1);
str[i] = Console.ReadLine();
}
Console.WriteLine(" ______________________________________\n");//分割线
for (int j = 0; j < num;j++ ) //排序过程
for (int i = j; i < num-1; i++)
{
if ( string.CompareOrdinal(str[i], str[i + 1]) > 0 )
{
string temp = str[i];
str[i] = str[i + 1];
str[i + 1] = temp;
}
}
Console.WriteLine("After the Sort:");//输入排序之后的字符串
for (int i=0; i < num; i++)
{
Console.WriteLine("{0}\n", str[i]);
}
}
}
}
[此贴子已经被作者于2007-3-24 22:33:32编辑过]