冒泡排序法
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace 程序算法
- {
-
-
-
-
-
-
- publicclass 冒泡算法
- {
- publicvoid Sort(int[] arr)
- {
- int temp;
- for (int i = 0; i < arr.Length; i++)
- {
- for (int j = 0; j < arr.Length - i-1; j++)
- {
-
-
-
-
-
-
-
- if (arr[j] < arr[j + 1])
- {
- temp = arr[j + 1];
- arr[j + 1] = arr[j];
- arr[j] = temp;
- }
- }
- }
- }
- publicstaticvoid Main(string[] args)
- {
- 冒泡算法 maoPao = new 冒泡算法();
- int[] array = newint[] { 1, 3, 2, 10, 13, 16, 42, 36, 77, 37, 99, 100 };
- maoPao.Sort(array);
- foreach (int k in array)
- {
- Console.Write(k);
- Console.Write(" ");
- }
- Console.WriteLine();
- }
- }
- }
posted @
2012-03-28 11:09
cyjch
阅读(
368)
评论()
编辑
收藏
举报