`
phoebird
  • 浏览: 113642 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

C# 冒泡排序

    博客分类:
  • C#
阅读更多
using System;
using System.Collections.Generic;
using System.Text;

namespace BubbleSortTest
{
    class BubbleSortTest
    {

        public static void Sort(int[] array)
        {
            int temp = 0;
            for (int i = 0; i < array.Length - 1; i++)
            {
                for (int j = 0; j < array.Length-1 - i; j++)
                {
                    if (array[j] < array[j+1])
                    {
                        temp = array[j];
                        array[j] = array[j + 1];
                        array[j + 1] = temp;
                    }
                }
            }
        }

    }
    class Test
    {
        static void Main(string[] args)
        {
             int[] array ={ 6, 4, 7, 2,9, 1 };
             BubbleSortTest.Sort(array);
            foreach(int index in array){
            
            Console.Write(index+"\t");
            }
            Console.Read();
        }
       
    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics