关于排序算法的问题可以在网上搜到一大堆,但是纯 JS 版比较零散,之前面试的时候特意整理了一遍,附带排序效率比较. //1.冒泡排序 var bubbleSort = function(arr) { for (var i = 0, len = arr.length; i < len - 1; i++) { for (var j = i + 1; j < len; j++) { if (arr[i] > arr[j]) { var temp = arr[i]; arr[i] = arr[j…
import random import time def bubble_sort(a): n=len(a) while n>1: for i in range(n-1): if a[i]>a[i+1]: temp=a[i] a[i]=a[i+1] a[i+1]=temp n+=-1 return a def insert_sort(a): n=len(a) for i in range(1,n): for j in range(i): if a[j]>a[i]: temp=a[i] d…
1. 利用循环打印如下图形 ***** **** *** ** * public class Main { public static void main(String[] args) { // TODO Auto-generated method stub int i = 5; while (i >= 0) { for (int j = i; j > 0; j--) System.out.print("*"); System.out.println(); i--; } }…