### 1.冒泡排序

``````function bubbleSort(arr) {
var arr = [ 3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48 ];	// 第一轮比较	for (let i = 0; i < arr.length - 1; i++) {
// 第二轮比较		let flag = true;		for (let j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
// 交换位置				int temp = arr[j];				arr[j] = arr[j + 1];				arr[j + 1] = temp;				flag = false;			}			if(flag){
break;			}		}	}	console.log(arr);}``````

### 2.选择排序

``````function SelectionSort() {
var arr = [ 3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48 ];	for (let i = 0; i < arr.length - 1; i++) {
let index =i;		for(let j=i+1;i<arr.length;j++){
if(arr[j]<arr[index]){
index = j;			}		}		//现在index中的下标为在i之后数值最小的下标我们只需要将这个值与i的值进行交换		let temp = arr[i];		 arr[i] = arr[index];		 arr[index] = temp;	}	console.log(arr);}``````

### 3.插入排序

`````` function InsertSort() {
var arr = [ 3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48 ];    for (let i = 0; i <= arr.length - 1; i++) {
//即将要插入的数值        let temp = arr[i]        //index为记录这个值应该插入的位置        let index;        for(var j=i-1;j>=0;j--){
if(arr[j]>temp){
arr[j+1]=arr[j];            }else{
break;            }        }        arr[j+1] = temp;    }    console.log(arr);}InsertSort();``````