曹永思

导航

冒泡法排序

        /// <summary>
        /// 冒泡法排序
        /// </summary>
        /// <param name="array">乱序的数字数组</param>
        /// <returns>排顺后的数组</returns>
        public int[] maobaofa(int[] array)
        { 
            int temp = 0;

            for (int i = 0; i < array.Length - 1; i++)
            {

                for (int j = i + 1; j < array.Length; j++)
                {

                    if (array[j] < array[i])
                    {

                        temp = array[i];

                        array[i] = array[j];

                        array[j] = temp;

                    }

                }
            }

            return array;
        }

 

posted on 2014-03-24 10:01  曹永思  阅读(192)  评论(0编辑  收藏  举报