2个回答
展开全部
前置 后置 冒泡
int mp[] = new int[1,2,12,22,58,48,0];
for (int i = 0; i < mp.length; i++) {
for (int j = 0; j < mp.length; j++) {
int temp;
if (mp[i] < mp[j]) {
temp = mp[j];
mp[j] = mp[i];
mp[i] = temp;
}
}
}
for (int i = 0; i < mp.length; i++) {
System.out.print(mp[i] + " ");
}
System.out.print("\n");
int mp[] = new int[1,2,12,22,58,48,0];
for (int i = 0; i < mp.length; i++) {
for (int j = 0; j < mp.length; j++) {
int temp;
if (mp[i] < mp[j]) {
temp = mp[j];
mp[j] = mp[i];
mp[i] = temp;
}
}
}
for (int i = 0; i < mp.length; i++) {
System.out.print(mp[i] + " ");
}
System.out.print("\n");
展开全部
//实现冒泡排序
int[] num=new int[]{100,34,20,44,56,76,99,10};
int temp;
for (int i = 0; i < num.length-1; i++) {
for (int j = 0; j <num.length-1-i; j++) {
if(num[j]>num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
//Arrays.sort(num); 使用此方法只能将数组中的元素升序排序
for (int i = 0; i < num.length; i++) {
System.out.print(" "+num[i]);
}
int[] num=new int[]{100,34,20,44,56,76,99,10};
int temp;
for (int i = 0; i < num.length-1; i++) {
for (int j = 0; j <num.length-1-i; j++) {
if(num[j]>num[j+1]){
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
//Arrays.sort(num); 使用此方法只能将数组中的元素升序排序
for (int i = 0; i < num.length; i++) {
System.out.print(" "+num[i]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询