标签:style blog color io os ar java for sp
java实现
package sort; public class BubbleSort { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] arr={70,80,31,37,10,1,48,60,33,80}; bubbleSort(arr); for(int i=0; i<arr.length; i++) System.out.print(arr[i]+" "); } private static void bubbleSort(int[] arr) { // TODO Auto-generated method stub int i,j; int temp; for(i=arr.length-1; i>0; i--) { for(j=0; j<i; j++) { if(arr[j]>arr[j+1]) { temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } } }
c++实现
#include<iostream> using namespace std; void bubbleSort(int a[],int len); int main() { int a[]={70,80,31,37,10,1,48,60,33,80}; int len=sizeof(a)/sizeof(int); bubbleSort(a,len); for(int i=0; i<len; i++) cout<<a[i]<<" "; } void bubbleSort(int a[],int len) { int i,j; int temp; for(i=len-1; i>0; i--) { for(j=0; j<i; j++) { if(a[j]>a[j+1]) { temp=a[j+1]; a[j+1]=a[j]; a[j]=temp; } } } }
标签:style blog color io os ar java for sp
原文地址:http://www.cnblogs.com/huangcongcong/p/4004097.html