排序 在线等 给出了12个数(ps:具体哪12个忘了),要求是:写一个函数快速对上述数据排序 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 才12个数,给个冒泡的:public class Sort {public static void main(String[] args) {int[] values = { 3, 1, 6, 2, 9, 0, 7, 4, 5, 15, 23, -8};sort(values);for (int i = 0; i <values.length; ++i) {System.out.println("Index:" + i + " Value: " + values[i]);}}public static void sort(int[] values) {int temp;for (int i= 0; i < values.length; ++i) { for(int j = 0; j < values.length - i -1; ++j) { if(values[j] > values[j + 1]) { temp= values[j]; values[j]= values[j + 1];values[j+ 1] = temp;}}}}} 1. public class BubleSort { 2. 3. public static void print(int [] temp) {//打印数组算法 4. for(int i=0;i<temp.length;i++) { 5. System.out.print(" " + temp[i]); 6. } 7. } 8. 9. public static void bubleSort(int [] a) {//冒泡排序 10. int length = a.length ; 11. int temp = 0; 12. for(int i=length-1;i>=1;i--) { 13. for(int j=0;j<=i-1;j++) { 14. if(a[j] > a[j+1]) { 15. temp = a[j] ; 16. a[j] = a[j+1] ; 17. a[j+1] = temp ; 18. } 19. } 20. } 21. } 22. 23. public static void main(String []args) {//注意本例中,排序int由命令行参数输入 24. int a[] = new int[args.length]; 25. for(int i=0;i<args.length;i++){ 26. a[i] = Integer.parseInt(args[i]) ; 27. } 28. BubleSort b = new BubleSort(); 29. b.bubleSort(a);//调用冒泡排序 30. b.print(a);//打印排序后结果 31. } 32. } public class PaiXu { public static void main(String[] args) { int[] array = {1,2,3,4,5,6,7,8,9,0};//12数自己再加两个·不想按了!上班ing int swap; for(int i=0;i<array.length;i++){ for(int j=0;j<i;j++){ if(array[i]>array[j]){ swap=array[i]; array[i]=array[j]; array[j]=swap; } } } for(int i=0;i<array.length;i++){ System.out.println(array[i]); } }} public class BubleSort { 2. 3. public static void print(int [] temp) { 4. for(int i=0;i<temp.length;i++) { 5. System.out.print(" " + temp[i]); 6. } 7. } 8. 9. public static void bubleSort(int [] a) {//冒泡排序 10. int length = a.length ; 11. int temp = 0; 12. for(int i=length-1;i>=1;i--) { 13. for(int j=0;j<=i-1;j++) { 14. if(a[j] > a[j+1]) { 15. temp = a[j] ; 16. a[j] = a[j+1] ; 17. a[j+1] = temp ; 18. } 19. } 20. } 21. } 22. 23. public static void main(String []args) {//注意本例中,排序int由命令行参数输入 24. int a[] = new int[args.length]; 25. for(int i=0;i<args.length;i++){ 26. a[i] = Integer.parseInt(args[i]) ; 27. } 28. BubleSort b = new BubleSort(); 29. b.bubleSort(a);//调用冒泡排序 30. b.print(a);//打印排序后结果 31. } 32. } public class Bubblesequence{ public static void main(String[] args) { int[] a = {5, 4, 31, 2, 1}; bubbleSequence(a); for(int i=0; i<a.length; i++) { System.out.print(a[i] + " "); } } //冒泡法排序 private static void bubbleSequence(int[] a) { int temp; for(int i=0; i<a.length-1; i++) { for(int j=0; j<a.length-1-i; j++) { if(a[j] > a[j+1]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } } //选择法排序 private static void xuanZe(int[] a) { int temp; for(int i=0; i<a.length-1; i++) { int k = i; for(int j=i+1; j<a.length; j++) { if(a[k] > a[j]) { k = j; } if(i != k) { temp = a[i]; a[i] = a[k]; a[k] = temp; } } } } } public class Paixu{ public static void main(String[] args) { int[] a = {5, 4, 31, 2, 1}; bubbleSequence(a); for(int i=0; i<a.length; i++) { System.out.print(a[i] + " "); } } //冒泡法排序 private static void bubbleSequence(int[] a) { int temp; for(int i=0; i<a.length-1; i++) { for(int j=0; j<a.length-1-i; j++) { if(a[j] > a[j+1]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } } //选择法排序 private static void xuanZe(int[] a) { int temp; for(int i=0; i<a.length-1; i++) { int k = i; for(int j=i+1; j<a.length; j++) { if(a[k] > a[j]) { k = j; } if(i != k) { temp = a[i]; a[i] = a[k]; a[k] = temp; } } } } } 为何大家不直接用sort()方法呢?直接调用java中的sort()方法,好像是用快排的! 这种小算法建议楼主自己研究,而不要COPY SWING中JTextArea动态显示数据的问题 c++与java得到不同的答案 Swing+derby仿QQ聊天软件 问一个java内存方面的问题 谁有JMF方面的资料??? 怎么判断这样的日期时间差超过5天呢?急,在线等 (在线)querydataset打开失败! 高分急救!!!!!!!!!!!!!!!! 求教:有人用做过把html文件中的表格提取出来,然后转换成xml文件的程序吗? 急:哪里有文件上传的Java源程序。拜托各位大虾了 swing滚动面板滚动 关于线程同步中synchronized的困惑
sort(values);for (int i = 0; i <values.length; ++i) {
System.out.println("Index:" + i + " Value: " + values[i]);
}
}public static void sort(int[] values) {
int temp;
for (int i= 0; i < values.length; ++i) {
for(int j = 0; j < values.length - i -1; ++j) {
if(values[j] > values[j + 1]) {
temp= values[j];
values[j]= values[j + 1];
values[j+ 1] = temp;
}
}
}}}
1. public class BubleSort {
2.
3. public static void print(int [] temp) {//打印数组算法
4. for(int i=0;i<temp.length;i++) {
5. System.out.print(" " + temp[i]);
6. }
7. }
8.
9. public static void bubleSort(int [] a) {//冒泡排序
10. int length = a.length ;
11. int temp = 0;
12. for(int i=length-1;i>=1;i--) {
13. for(int j=0;j<=i-1;j++) {
14. if(a[j] > a[j+1]) {
15. temp = a[j] ;
16. a[j] = a[j+1] ;
17. a[j+1] = temp ;
18. }
19. }
20. }
21. }
22.
23. public static void main(String []args) {//注意本例中,排序int由命令行参数输入
24. int a[] = new int[args.length];
25. for(int i=0;i<args.length;i++){
26. a[i] = Integer.parseInt(args[i]) ;
27. }
28. BubleSort b = new BubleSort();
29. b.bubleSort(a);//调用冒泡排序
30. b.print(a);//打印排序后结果
31. }
32. }
int[] array = {1,2,3,4,5,6,7,8,9,0};//12数自己再加两个·不想按了!上班ing
int swap;
for(int i=0;i<array.length;i++){
for(int j=0;j<i;j++){
if(array[i]>array[j]){
swap=array[i];
array[i]=array[j];
array[j]=swap;
}
}
}
for(int i=0;i<array.length;i++){
System.out.println(array[i]);
}
}}
2.
3. public static void print(int [] temp) {
4. for(int i=0;i<temp.length;i++) {
5. System.out.print(" " + temp[i]);
6. }
7. }
8.
9. public static void bubleSort(int [] a) {//冒泡排序
10. int length = a.length ;
11. int temp = 0;
12. for(int i=length-1;i>=1;i--) {
13. for(int j=0;j<=i-1;j++) {
14. if(a[j] > a[j+1]) {
15. temp = a[j] ;
16. a[j] = a[j+1] ;
17. a[j+1] = temp ;
18. }
19. }
20. }
21. }
22.
23. public static void main(String []args) {//注意本例中,排序int由命令行参数输入
24. int a[] = new int[args.length];
25. for(int i=0;i<args.length;i++){
26. a[i] = Integer.parseInt(args[i]) ;
27. }
28. BubleSort b = new BubleSort();
29. b.bubleSort(a);//调用冒泡排序
30. b.print(a);//打印排序后结果
31. }
32. }
public class Bubblesequence
{
public static void main(String[] args)
{
int[] a = {5, 4, 31, 2, 1};
bubbleSequence(a);
for(int i=0; i<a.length; i++)
{
System.out.print(a[i] + " ");
}
}
//冒泡法排序
private static void bubbleSequence(int[] a)
{
int temp;
for(int i=0; i<a.length-1; i++)
{
for(int j=0; j<a.length-1-i; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
} }
//选择法排序
private static void xuanZe(int[] a)
{
int temp;
for(int i=0; i<a.length-1; i++)
{
int k = i;
for(int j=i+1; j<a.length; j++)
{
if(a[k] > a[j])
{
k = j;
}
if(i != k)
{
temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
}
}
}
public class Paixu
{
public static void main(String[] args)
{
int[] a = {5, 4, 31, 2, 1};
bubbleSequence(a);
for(int i=0; i<a.length; i++)
{
System.out.print(a[i] + " ");
}
}
//冒泡法排序
private static void bubbleSequence(int[] a)
{
int temp;
for(int i=0; i<a.length-1; i++)
{
for(int j=0; j<a.length-1-i; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
} }
//选择法排序
private static void xuanZe(int[] a)
{
int temp;
for(int i=0; i<a.length-1; i++)
{
int k = i;
for(int j=i+1; j<a.length; j++)
{
if(a[k] > a[j])
{
k = j;
}
if(i != k)
{
temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
}
}
}