对这几个基础排序算法进行梳理,便于以后查看。 /** * * 冒泡排序 * 从末尾开始相邻两数相互比较大小,满足条件就交换位置。循环每进行一次,即可确定第i位数的值。 *冒泡排序的时间复杂度为O(n^2)。 * */ function bubbleSort(arr){ if(arr == null
分类:
编程语言 时间:
2016-03-07 18:47:19
阅读次数:
218
1.冒泡排序: (1)比较相邻的元素。如果第一个比第二个大,就交换他们两个。 (2)外面再套个循环就行。 算法复杂度:O(N2) 不罗嗦,上代码: //冒泡排序(两两交换,外加一个外循环) public static void bubbleSort(int sortData[]){ int i,j,
分类:
编程语言 时间:
2016-03-07 16:26:57
阅读次数:
162
基本思想 首先第一个元素和第二个元素比較,假设第一个大。则二者交换,否则不交换;然后第二个元素和第三个元素比較。假设第二个大,则二者交换,否则不交换……一直按这样的方式进行下去。终于最大的那个元素被交换到了最后。一趟冒泡排序完毕。 代码 public void BubbleSort(int[] a,
分类:
编程语言 时间:
2016-03-06 12:40:35
阅读次数:
270
四种排序算法的时间比较 #include<iostream> #include<time.h> using namespace std; template<class T> inline void Swap(T& a, T& b); template<class T> void BubbleSort
分类:
编程语言 时间:
2016-03-05 23:29:41
阅读次数:
316
对于一个int数组,请编写一个冒泡排序算法,对数组元素排序。
给定一个int数组A及数组的大小n,请返回排序后的数组。
测试样例:
输入数组:[1,2,3,5,2,3],6
输出数组:[1,2,2,3,3,5]
class BubbleSort {
public:
int* bubbleSort(int* A, int n) {
...
分类:
编程语言 时间:
2016-03-05 14:48:45
阅读次数:
245
1 package com.hanqi; 2 public class BubbleSort 3 { 4 public static void main(String[] args) 5 { 6 //冒泡排序 7 int[]a=new int [] {11,23,9,34,89,70,39,21,1
分类:
编程语言 时间:
2016-03-01 00:50:58
阅读次数:
297
1.冒泡法排序 /* * 冒泡法排序 :在要排序的一组数中,对当前还未排好序的范围内的全部数,自左而右对相邻的两个数 * 相邻的两个数的交换 */ public void bubbleSort(int[] num) { int temp = 0; for(int i=0;i<num.length-1
分类:
编程语言 时间:
2016-02-27 23:32:30
阅读次数:
180
// 2016_2_23_bubbleSort.cpp : Defines the entry point for the console application.//冒泡排序算法,两两比较,小的排到前面,大的排到后面 #include "stdafx.h" void BubbleSort(int
分类:
编程语言 时间:
2016-02-23 12:42:02
阅读次数:
144
//BubbleSort.go package main import "fmt" func main() { values := []int{4, 93, 84, 85, 80, 37, 81, 93, 27,12} fmt.Println(values) BubbleAsort(values)
分类:
编程语言 时间:
2016-02-22 22:17:37
阅读次数:
256
<script> function bubbleSort(array) { var i, j, temp, len = array.length; for (i = 0; i < len; i++) { for (j = 0; j < len; j++) { if (array[i] < array
分类:
编程语言 时间:
2016-02-16 19:02:44
阅读次数:
122