// TODO: 插入排序 int i, prei, tmp; for (i = 1; i < ns.length; ++i) { // 1. 找插入位置, 把前面的移动到后面 tmp = ns[i]; prei = i - 1; // 把 '<' 改成 '>' 就是升序 while (prei >= 0 && ns[prei] < tmp) { ns[prei + 1] = ns[prei]; prei -= 1; } // 2. 插入 ns[prei + 1] = tmp; }
Sign in to make a reply
最初雨叶_梦