zoukankan      html  css  js  c++  java
  • 插入排序

    基本思想:
        每次将一个待排序的数据元素,插入到前面已经排好序的数列中的适当位置,使数列依然有序;直到待排序数据元素全部插入完为止。

    实例代码:
    public class InsertionSorter 

         
    public void Sort(int [] list) 
        

        
    for(int i=1;i<list.Length;i++
         
    {
            
    int t=list[i]; 
            
    int j=i; 

           
    while((j>0)&&(list[j-1]>t)) 
            

               list[j]
    =list[j-1]; 
                
    --j; 
           }
     

        list[j]
    =t; 
        }
     
      }
     
    }
     

    public class MainClassTest3 

        
    public static void Main() 
        

            
    int[] iArrary=new int[]{1,13,3,6,10,55,98,2,87,12,34,75,33,47}
            InsertionSorter ii
    =new InsertionSorter(); 
            ii.Sort(iArrary);
            
    for (int m = 0; m < iArrary.Length; m++)
            
    {
                Console.WriteLine();
                Console.Write(
    "{0}", iArrary[m]);
            }


            Console.WriteLine(); 
        }
     
    }
     
    运行结果:


  • 相关阅读:
    类与类之间的关系图
    UML介绍
    数据建模
    状态图
    部署图
    用例图
    业务建模
    时序图
    postgresql 维护手册
    ashx文件的使用(转)
  • 原文地址:https://www.cnblogs.com/abcdwxc/p/972278.html
Copyright © 2011-2022 走看看