110,539
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace BubbleSort
{
class Program
{
static void Main(string[] args)
{
StreamReader sr=new StreamReader("d:\\1.txt");
string line="";
string[] a;
line=sr.ReadToEnd();
a=line.Split(',');
for(int j=a.Length-1;j>=0;j--)
{
for (int i = 0; i < j; i++)
{
if (int.Parse(a[i]) > int.Parse(a[i + 1]))
{
int b = int.Parse(a[i]);
int.Parse(a[i]) = int.Parse(a[i + 1]);
int.Parse(a[i + 1]) = b;
}
}
}
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}
}
}
}