冒泡排序BubbleSort

2/10/2017来源:ASP.NET技巧人气:858

package w3ang.algorithms;
import java.util.ArrayList;
import java.util.Collections;
public class BubbleSort 
{
	public BubbleSort(ArrayList<Integer> arrayList) 
	{
		int sizeA=arrayList.size();
		for(int i=sizeA-1;i>=0;i--)
		{
			for(int j=0;j<i;j++)
			{
				if(arrayList.get(j)>arrayList.get(j+1))
				{
					Collections.swap(arrayList, j, j+1);
				}
			}
		}
	}
}