1.选择排序 import java.util.Scanner ; public class Selection{ //选择排序 public static void selectionSort(Comparable[] a){ int n = a.length ; for (int i=0;i<n-1;i++) { int min = i ; for (int j=i+1;j<n;j++) { if (less(a[j],a[min])) { min = j ; } } exch(a,i,m
1.冒泡排序: 思路:将相邻的逆序元素交换为顺序排列,直到整个序列有序,算法如下: /** * 冒泡排序-最初实现,时间复杂度O(n^2) * @param arr 待排序的数组 * @param lo 待排序区间的起始位置 * @param hi 待排序区间的结束位置 */ public static void bubbleSort(int[] arr, int lo, int hi) { //对序列进行规模n-1次扫描 for (int i = lo; i < hi - 1; i++) {
//以下依次是冒泡.选择.插入排序 var n,i:longint; a:array[0..20] of longint;procedure BUB;var i,j,t:longint;begin for i:=1 to n-1 do for j:=1 to n-i do if a[j]>a[j+1] then begin t:=a[j]; a[j]:=a[j+1]; a[j+1]:=t; end;end;procedure SEL;var i,j
Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards. The workers will compare their rewards ,and s