|
如果你是测试leader,有一些算法或是程序你应该学会,它能够反映出你开发的能力,同时可以活跃一下你的脑筋.
1. 冒泡排序
- package com.myprogram.utility;
- /*
- * @author xyshang
- * @date 2007-01-18
- * @function sort numbers from small to large
- */
- public class SortNumber {
-
- //冒泡排序法
- public static int[] SortMaoPao(int[] numbers){
- int len = numbers.length;
- int temp;
- for(int i=0;i<len;i++){
- for(int j=0;j<len-i-1;j++){
- if(numbers[j]>numbers[j+1]){
- temp = numbers[j];
- numbers[j] = numbers[j+1];
- numbers[j+1] = temp;
- }
- }
- }
- return numbers;
- }
- public static void outputNumber(int[] lists){
- for(int i=0;i<lists.length;i++){
- System.out.print(lists[i]);
- }
- }
- public static void main(String[] args){
- int[] numbers = {5,4,3,2,9,1,0,6,8,7};
- System.out.print("Original Numbers is \t: ");
- outputNumber(numbers);
- System.out.print("\nSorted Numbers is \t: ");
- outputNumber(SortMaoPao(numbers));
- }
- }
复制代码 |
|