
本文共 3882 字,大约阅读时间需要 12 分钟。
���������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ ������ ���������������������������������������������javascript���java���������������������
���������
������������������������������������������������������������������������������������������
��������������� ��������������������� ���������������
��������������� ������������������������������������������������������������������������������
��������������� ��������������������������������������������������������������������������������������� ������������������������������������������������������������������......
��������������� ������������ ���������������������������������
������������������������������������������������������
��������������� ������������������������������������������
��������������� ������������������������������ ��������������������������� ���������������
���������
������������������������������ ��� ���������������������������������,���������������������,���������������������������������������������������������������,���������������������������������
��������������������� ������������������������������������������������������������������������������������������������������������������
���������javascript���������
������������������
function insertSort(arr){ for(var i = 1;i0){ if( temp < arr[j-1] ){ //��������������������������������� var a = arr[j-1]; //������������������������������ arr[j-1] = arr[j]; arr[j] = a; j--; //���������j j���������-- }else{ j=0; //������������������������ ��������������������� } } } return arr; }
��������� ������ [6,1,2,7,9,3,4,5,10,8,8,9] ������������������������ [1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10]
���������������while������������:
������
function insertSort(arr){ //arr = [6,1,2,7,9,3,4,5,10,8,8,9] for(var i = 1;i0){ if( temp < arr[j-1] ){ // 1 < 6 ������ true var a = arr[j-1]; arr[j-1] = arr[j]; arr[j] = a; //������1 - 6 j--; //i-- i=0 ������������������ ��������� arr = [1,6,2,7....] ���������2 ������������ }else{ j=0; } } } return arr; }
java������������
������
public class SortUtil { //������������������������ public static void sort(Comparable[] a){ for(int i=1;i0){ if(less(tem,a[j-1])){������//less������������ tem��������������������� exch(a,j,j-1); j--; }else{ j=0; } } } } /* * compareTo ������������ * @param {Comparable} v ������v������w ������true * @param {Comparable} w ������v������������w ������false * @return {boolean} ������������������ * * */ public static boolean less(Comparable v,Comparable w){ return v.compareTo(w) < 0; } /* * compareTo ������������ * @param {Comparable[]} a ��������������������������� * @param {int} i ������1������ * @param {int} j ������2������ * * */ public static void exch(Comparable[] a,int i,int j){ Comparable t = a[i]; a[i] = a[j]; a[j] = t; } public static void show(Comparable[] a){ for(int i=0;i
���������
��������� ������������������������������������������������,���������������������,���������������������������������������������������������������,���������������������������������
��������� ������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
