算法

冒泡排序

 

int temp ;
        
        int array[10] = {9,8,7,6,5,4,3,2};
        
        for (int i = 0; i < 8; i ++) {
            
            for (int j = i+1; j < 8; j ++) {
                
                if (array[i] > array[j]) {
                    
                    temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                    
                }
                
            }
            
        }
        
        for (int i = 0; i < 8; i ++) {
            
            printf("%d\n",array[i]);
            
        }

 

 
 
posted @ 2016-06-07 22:41  iOS张文权  阅读(219)  评论(0编辑  收藏  举报