zoukankan      html  css  js  c++  java
  • 插入排序(C#数据结构学习七)

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace SoloDataStructure
    {
        
    class MyInsertSort
        
    {
            
    //插入排序
            
    //这个简单不多注释
           static void InsertSort ( int[] array)
            
    {
                
    //递增排序
                 int temp; 
                 
    int i, j,n;
                 n 
    = array.Length;
               
                 
    for ( i = 1; i < n; i++ )
                  
    {
                  temp 
    = array[i];    //设置监哨
                   for ( j = i;  j > 0; j-- )  
                    
    if ( temp < array[j-1]) 
                        array[j] 
    = array[j-1];   //记录后移
                    else
                        
    break;
                     array[j] 
    = temp;    //插入array[i];
                 }

            }

            
    static void Main(string[] args)
            
    {
                
    int[] arr = new int[] 49,38,65,97,76,13,27,49};
                Console.Write(
    "原数组数据顺序:");
                
    foreach (int i in arr)
                
    {
                    Console.Write(i 
    + ".");
                }

                InsertSort(arr);
                Console.Write(
    "\n插入排序后数组数据顺序:");
                
    for (int i = 0; i<arr.Length; i++)
                    Console.Write(arr[i]
    +".");
                Console.ReadLine();

            }

        }

    }
  • 相关阅读:
    mac的端口被占用
    php中的运算符、控制结构
    文档模式影响浏览器的渲染
    ubuntu 命令 tips 来自于 ubuntu中文论坛
    用好 Emacs 中的 register
    [转载] Rsync命令参数详解
    使用 python 遍历目录下的文件
    灵活的左移位( << )操作
    使用 iperf 测试两台机器间的最大带宽
    Emacs server 新启动方式 (仅在emacs daemon未启动时才启动daemon)
  • 原文地址:https://www.cnblogs.com/solo/p/609673.html
Copyright © 2011-2022 走看看