---
title: "Ruby实现冒泡排序"
author: "suxu"
date: "2013-01-07T17:33:33Z"
tags: []
categories: ["编程语言"]
slug: "ruby"
draft: false
lastmod: "2013-01-07T17:34:10Z"
id: 1765586
url: "https://suxu.iteye.com/blog/1765586"
---

ruby

 

```
#冒泡排序
def bulle_sort
  a = [40,12,23,543,53,2,77,34]
  i =0
  while (i<a.length)
    j=i+1
    while(j<a.length)
      if a[i]>a[j]
        temp = a[j]
        a[j] = a[i]
        a[i] = temp
      end
      j=j+1
    end
    i=i+1
  end
  
end
```

 java

 

```
public static void main(String[] args) {
		int [] a = {40,12,23,543,53,2,77,34};
		int temp = 0;
		for(int i =0;i<a.length;i++){
			for(int j=i+1;j<a.length;j++){
				if (a[i]> a[j]) {
				  temp = a[i];
				  a[i] = a[j];
				  a[j] = temp;
			   }
			}
		}
		
}
```