keyword: bubble sort | read IO file | linq sort using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace BubbleSort { class Program { static void Main(string[] args) { BubbleMan mb = new BubbleMan("data.txt"); //int[] temp=mb.BubbleSort(); int[] temp = mb.LinqSort(); } } class BubbleMan { protected int[] IntArray; //protected int[] current; public BubbleMan(string file) { if (File.Exists(file)) { string str = File.ReadAllText(file); str = str.Replace("/r/n", " "); string[] temp = str.Split(' '); IntArray = Array.ConvertAll(temp, new Converter<string, int>(StrToInt)); } } public static int StrToInt(string str) { return int.Parse(str); } public int[] BubbleSort() { if (!IntArray.Length.Equals(0)) { for (int i = 0; i < IntArray.Length; i++) { for (int j = IntArray.Length-1; j >i; j--) { if (IntArray[i] < IntArray[j]) { int temp = IntArray[j]; IntArray[j] = IntArray[i]; IntArray[i] = temp; } } } } return IntArray; } public int[] LinqSort() { //int[] result=new int[IntArray.Length]; List<int> result = new List<int>(); var temp = from x in IntArray orderby x select x; foreach (int t in temp) { result.Add(t); } return result.ToArray(); } } }