ITeye博客

java算法

windshjw · 2011-02-08 14:34 · 编程语言 · Markdown

package sortTest;

public class BubbleTest {

/**
 * @param args
 */
public static void main(String args)
{
	int num = new int{ 3, 1, 5, 4, 2, 6, 0, 9 };
	int result = sort(num);
	for(int i = 0 ; i< result.length;i++){
		System.out.println(result*);
	}
	

}

public static int sort(int num){
	for(int i =0; i< num.length-1 ; i++){
		for(int j=0; j<num.length-1-i;j++){
			int temp = 0;
			if(num<num){
				temp=num;
				num=num;
				num=temp;
			}
		}
		
		
	}
	
	return num;
}

}

package sortTest;

public class InsertSortTest {

/**
 * @param args
 */
public static void main(String args)
{
	int num = new int
	{ 3, 1, 5, 4, 2, 6, 0, 9 };
	insertSort(num);
	for(int i = 0 ; i< num.length;i++){
		System.out.println(num*);
	}
}

public static int insertSort(int num){
	int j = 0;
	for(int i =0 ; i< num.length -1; i++){
		j = i;
		int temp = num*;
		
		for(;j>0; j--){
			if(num>temp){
				num=num;
			}else{
				break;
			}
			
		}
		num=temp;
		
	}
	
	
	return num;
}

}

package sortTest;

public class QuickSortTest {

/**
 * @param args
 */
public static void main(String args)
{
	int num = new int{ 3, 1, 5, 4, 2, 6,0,9 };
	int result = quickSort(num, 0, num.length - 1);
	for(int i = 0 ; i< result.length;i++){
		System.out.println(result*);
	}
}

public static int quickSort(int num, int left, int right)
{
	if (left < right)
	{
		int singleSort = singleSort(num, left, right);
		
		quickSort(num, left, singleSort-1);
		quickSort(num, singleSort+1, right);
	}

	return num;
}

public static int singleSort(int num, int left, int right)
{
	int x = num;
	int i = left;
	int j = right;
	while (i < j)
	{
		while (i < j && num >= x)
		{
			j--;
		}
		num* = num;
		while (i < j && num* <= x)
		{
			i++;
		}
		num = num*;
	}
	num*=x;
	
	return i;
}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。