冒泡排列数组 采用冒泡排序对如下数组排序 String[] arr = { "Now", "is", "the", "time", "for","all", "good", "men", "to", "come", "to", "the", "aid", "of", "their", "country" }; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class BunbleSort { public static void main(String[] args) { // TODO Auto-generated method stub String[] arr = { "Now", "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "their", "country" }; print(BunbleSort(arr)); } // 冒泡排序 public static String[] BunbleSort(String[] data) { for (int i = 0; i < data.length; i++) { for (int j = 0; j < data.length - i - 1; j++) { if (data[j].compareToIgnoreCase(data[j + 1]) > 0) { String temp = data[j]; data[j] = data[j + 1]; data[j + 1] = temp; } } } return data; } // 打印数组 public static void print(String[] data) { for (String s : data) System.out.print(s + " "); System.out.println(); }} 输出结果:aid all come country for good is men Now of the the their time to to 为什么在struts2官方源码中没有ActionSupport 重金悬赏EqualsBuilder 这个东西到哪里去了 js脚本 SSH中的DAO组件测试? 求高手指导,SSH整合,annotation注入失败 myEclipse4.1 + weblogic8.1 如何调试JSP代码? 准备制作OA系统(开源),求各方面的资料 假如同时调用两个有状态session bean,这两个bean之间怎样能通信? 哪里有SQL Server 2000 JDBC驱动程序的帮助文档? jsp救助 struts2前台分页 问特简单问题,白送分啦!!!
// TODO Auto-generated method stub
String[] arr = { "Now", "is", "the", "time", "for", "all", "good",
"men", "to", "come", "to", "the", "aid", "of", "their",
"country" };
print(BunbleSort(arr));
} // 冒泡排序
public static String[] BunbleSort(String[] data) {
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data.length - i - 1; j++) {
if (data[j].compareToIgnoreCase(data[j + 1]) > 0) {
String temp = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
}
} }
return data;
} // 打印数组
public static void print(String[] data) {
for (String s : data)
System.out.print(s + " ");
System.out.println();
}
}