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


  • 相关阅读:
    nginx配置虚拟主机
    nginx 中http协议的相关配置
    nginx的性能优化
    编译安装NGINX-1.21.0
    nginx命令使用
    编译安装NGINX1.16.1
    nginx: [emerg] getpwnam("nginx") failed
    swift选择类或结构体
    工具与网址
    WARNING: CPU: 0 PID: 1 at ./arch/x86/include/asm/fpu/internal.h:373
  • 原文地址:https://www.cnblogs.com/abcdwxc/p/972278.html
Copyright © 2011-2022 走看看