冒泡排序,排序字符
2014-01-18 14:19
197 查看
package com.order.test; public class Order { public static void main(String[] args) { String [] datas=new String[]{"75","新浪","70","中华人民","90","95","85","80","X","L","XL","XML","12","A","B","D","Z","Y","X","110","150","140","130","99"}; for (int i = 0; i < datas.length -1; i++){ //最多做n-1趟排序 for(int j = 0 ;j < datas.length - i - 1; j++){ //对当前无序区间score[0......length-i-1]进行排序(j的范围很关键,这个范围是在逐步缩小的) String value1=datas[j]; String value2=datas[j+1]; if(checkNumber(value1)&&checkNumber(value2)){ if(Integer.parseInt(value1)>Integer.parseInt(value2)){ String temp = datas[j]; datas[j] = datas[j + 1]; datas[j + 1] = temp; } }else if(checkNumber(value2)&&!checkNumber(value1)){ String temp = datas[j]; datas[j] = datas[j+1]; datas[j+1] = temp; } } } System.out.print("最终排序结果:"); for(int a = 0; a < datas.length; a++){ System.out.print(datas[a] + " "); } } private static boolean checkNumber(String key){ for(int i=0;i<key.length();i++){ char ch=key.charAt(i); if(ch<'0'||ch>'9'){ return false; } } return true; } }
结果:
最终排序结果:12 70 75 80 85 90 95 99 110 130 140 150 新浪 中华人民 X L XL XML A B D Z Y X
相关文章推荐
- 第十三周项目四 数组的排序(对字符数组进行冒泡排序)
- 字符的排序(冒泡排序,选择排序)
- 冒泡排序对字符串字符进行排序并输出
- 【第3节】简单排序--冒泡排序
- 十四周——字符数组排序
- 交换排序之冒泡排序
- 排序-冒泡排序简单实现
- 【算法设计与分析基础】5、冒泡排序与选择排序
- Java实现排序(快速排序、冒泡排序、选择排序、基数排序、插入排序)
- 数据结构-冒泡排序和直接插入排序
- java自带的sort方法实现文件内字符的排序
- 排序-冒泡排序
- C/C++ 排序之一(冒泡排序、选择排序、交换排序)
- 自己实现一个bubble_sort(冒泡排序),可以完成不同类型数据的排序
- 可视化排序实践之冒泡排序
- 一维数组的排序方法----冒泡排序
- 归并排序比冒泡排序快上好多倍
- 排序:冒泡排序
- 排序之冒泡排序
- java数组扩展练习及冒泡排序,选择排序和折半查找