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(); 
        }
     
    }
     
    运行结果:


  • 相关阅读:
    Vue 路由的编程式导航与history模式
    Vue 路由配置、动态路由
    Vue 组件传值
    Vue 组件以及生命周期函数
    Vue 封装js
    记一次proc_open没有开启心得感悟
    面向内容的标记语言--markdonw
    浅谈索引
    mysql主从配置
    centos7下操作防火墙
  • 原文地址:https://www.cnblogs.com/abcdwxc/p/972278.html
Copyright © 2011-2022 走看看