- /**
- * insertion sort
- * @param A the array which is going to be sorted
- */
- public void sort(int[] A)
- {
- int i = 0, j = 0, value = 0;
- for(i = 1; i < A.length; i++)
- {
- value = A[i]; //key value to compare
- j = i - 1;
- while(j >= 0 && A[j] > value)
- {
- //sort the array from small to big
- A[j+1] = A[j];
- j--;
- }
- A[j+1] = value;
- }
- }
Insertion Sort
最新推荐文章于 2021-09-18 19:55:30 发布