使用冒泡排序对一维数组进行排序

实现效果:

  

实现原理:

  

实现代码:

        //定义冒泡排序方法
        public int[] sory(int[] intArray)
        {
            for(int i=0;i<intArray.Length-1;i++){
                for (int j = 0; j < intArray.Length - i;j++ )
                {
                    if (intArray[i] > intArray[i+1]) {
                        int temp = intArray[i];
                        intArray[i] = intArray[i+1];
                        intArray[i+1] = temp;
                    }
                }
            }       return intArray;
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10061995.html