zoukankan      html  css  js  c++  java
  • 冒泡排序

    冒泡算法:
        基本思想:两两比较待排序数据元素的大小,发现两个数据元素的次序相反时即进行交换,直到没有反序的数据元素为止。
    代码实现:
     public class BubbleSorter 

        

           
    public void Sort(int [] list) 

        

            
    int i,j,temp; 

            
    bool done=false

            j
    =1

            
    while((j<list.Length)&&(!done)) 

            

             done
    =true

            
    for(i=0;i<list.Length-j;i++
            

            
    if(list[i]>list[i+1]) 
            

            done
    =false
            temp
    =list[i]; 
            list[i]
    =list[i+1]; 
            list[i
    +1]=temp; 

            }
     
            }
     

            j
    ++; }
     

        }
     
       }
     

    public class MainClassTest 

    public static void Main() 



    int[] iArrary=new int[]{34,3,5,6,43,56,2,87,12,34,75,33,47}

    BubbleSorter sh
    =new BubbleSorter(); 

    sh.Sort(iArrary); 

    for(int m=0;m<iArrary.Length;m++

    Console.Write(
    "{0} ",iArrary[m]); 

    Console.WriteLine(); 

    }

    }
     
    运行结果:
            
  • 相关阅读:
    Struts2框架
    读者写者问题
    哲学家就餐问题
    理解中断
    理解处理机调度
    理解死锁
    理解进程
    Linux CentOS 6.7 挂载U盘
    家庭-养老院模型理解IOC和DI
    Bash基础
  • 原文地址:https://www.cnblogs.com/abcdwxc/p/970269.html
Copyright © 2011-2022 走看看