我是靠谱客的博主 还单身小天鹅,这篇文章主要介绍TypeScript版冒泡,现在分享给大家,希望可以做个参考。

maopao(arr: number[], num: number): number[] {
        let item = 0;
        let temp;
        for (var index = 1; index < arr.length - num; index++) {
            var element = arr[index];
            if (arr[index] < arr[index - 1]) {
                temp = arr[index];
                arr[index] = arr[index - 1];
                arr[index - 1] = temp;
                item++;
            }
        }
        if (item == 0)
            return arr;
        else
            return this.maopao(arr, ++num);
    }

最后

以上就是还单身小天鹅最近收集整理的关于TypeScript版冒泡的全部内容,更多相关TypeScript版冒泡内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部