Part2-->插入排序

插入排序--->倒置的数量很少时,插入排序

很可能比本章中的其他任何算法都要快。

j控制从剩下的元素中依次取数,每次取出一个数,将这个数插入到前面已经排好序的元素中,i控制排好序的元素的边界

 

public class Insertion {
    public static void sort(Comparable[] a) {
        int N = a.length;
        for (int i = 1; i < N; i++) {
            for (int j = i; j>0 && less(a[j], a[j-1]); j--) {
                exch(a, j, j-1);
            }
        }
    }
}

 

转载于:https://www.cnblogs.com/stitchZsx/p/9887341.html

请你在以下zotero的代码基础上,进行修改,我要求的参考文献格式是:<?xml version="1.0" encoding="utf-8"?> <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only" default-locale="en-GB"> <info> <title>Nano-Micro Letters</title> <id>http://www.zotero.org/styles/nano-micro-letters</id> <link href="http://www.zotero.org/styles/nano-micro-letters" rel="self"/> <author> <name>Modified for Nano-Micro Letters</name> </author> <category citation-format="numeric"/> <category field="science"/> <category field="generic-base"/> <updated>2025-03-17T00:00:00+00:00</updated> </info> <macro name="title"> <text variable="title" text-case="sentence"/> </macro> <macro name="author"> <names variable="author"> <name form="long" and="symbol" delimiter=", " initialize-with=". " name-as-sort-order="all"/> <label form="short" prefix=", "/> <et-al/> </names> </macro> <macro name="container-title"> <text variable="container-title"/> </macro> <macro name="issuance"> <group delimiter="; "> <date variable="issued"> <date-part name="year"/> </date> <group delimiter=":"> <text variable="volume"/> <text variable="issue" prefix="(" suffix=")"/> </group> <text variable="page"/> </group> </macro> <macro name="access"> <choose> <if variable="DOI"> <text variable="DOI" prefix="https://doi.org/"/> </if> </choose> </macro> <citation collapse="citation-number"> <sort> <key variable="citation-number"/> </sort> <layout vertical-align="sup" delimiter=","> <text variable="citation-number"/> </layout> </citation> <bibliography et-al-min="6" et-al-use-first="1" second-field-align="flush" entry-spacing="0" line-spacing="2"> <layout suffix="."> <text variable="citation-number" suffix="."/> <group delimiter=" "> <text macro="author" suf
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值