排序算法(03. 选择排序)

1.什么是冒泡排序:

![在这里插入图片描述]( https://img-blog.csdnimg.cn/20200413152919322.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjQ5ODEwMg==,size_16,color_FFFFFF,t_70)

2.代码实现:

//交换两个位置数据方法
            ArrayList.prototype.swap = function(m, n) {
                var temp = this.array[m]
                    this.array[m] = this.array[n]
                    this.array[n] = temp
            }
            //排序算法
          // 2.选择排序
            ArrayList.prototype.selectSort = function() {
                var length = this.array.length
                for (var j = 0; j < length - 1; j++) { 
                    var min =j
                    for (var i = min + 1; i < length; i++) {
                        if (this.array[i] < this.array[min]) {
                            min = i
                        }
                    }
                    this.swap(j, min)
                }
            }

3.实现过程图解:

![]( https://img-blog.csdnimg.cn/20200413153025641.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjQ5ODEwMg==,size_16,color_FFFFFF,t_70)

4.时间复杂度:

![nimg.cn/20200413134348432.png)]( https://img-blog.csdnimg.cn/20200413153059870.png?x-oss-process=image/watermark ,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjQ5ODEwMg==,size_16,color_FFFFFF,t_70)

posted @ 2020-04-13 15:32  jacksonni  阅读(149)  评论(0)    收藏  举报