Java Bubble Sorting Code

Source: Internet
Author: User

 

Public Class ...{

Public static void sort (string Arg )...{
String [] ARGs = Arg. Split (",");
For (INT I = 0; I <args. length; I ++ )...{
For (Int J = 0; j <args. length-i-1; j ++ )...{
Int A = integer. parseint (ARGs [J]);
Int B = integer. parseint (ARGs [J + 1]);
If (A> B )...{
A = a ^ B;
B = a ^ B;
A = a ^ B;
}
ARGs [J] = string. valueof ();
ARGs [J + 1] = string. valueof (B );
}
}
For (INT I = 0; I <9; I ++ )...{
System. Out. Print (ARGs [I] + ",");
}
}

Public static void main (string [] ARGs )...{
Sort (", 65 ");
}


}

Improved Type I
A. Java

Import java. util .*;
Public Class {
Static int CI = 0;
Public static void sort (string Arg, int flag ){
String [] ARGs = Arg. Split (",");
Long C1 = calendar. getinstance (). gettimeinmillis ();
_ Out:
For (INT I = 0; I <args. length; I ++ ){
Int n = 0;
For (Int J = 0; j <args. length-i-1; j ++ ){
Int A = integer. parseint (ARGs [J]);
Int B = integer. parseint (ARGs [J + 1]);
CI ++;
If (A> B ){
A = a ^ B;
B = a ^ B;
A = a ^ B;
N ++;
}

ARGs [J] = string. valueof ();
ARGs [J + 1] = string. valueof (B );
}

If (n = 0 & flag = 1 ){
Break _ out;
}

}
For (INT I = 0; I <args. length; I ++ ){
System. Out. Print (ARGs [I] + ",");
}
Long C2 = calendar. getinstance (). gettimeinmillis ();

Long d1 = c2-c1;
System. Out. println ();
System. Out. println ("------------------------------------------------------");
System. Out. println ("running time:" + D1 + "millisecond, loop" + CI + "times ");
}

Public static void main (string [] ARGs ){
Sort (",", integer. parseint (ARGs [0]);
}

}

B. Java testing class

Import java. Io .*;
Import java. util .*;
Public Class B
{
Public static void main (string [] ARGs ){
List li = new arraylist ();
Random RND = new random ();
// Generate 10000 unordered non-repeating Integers
For (INT I = 0; I <10000; I ++ ){
Int A = RND. nextint (10000 );
While (Li. Contains (New INTEGER ())){
A = RND. nextint (10000 );
}
Li. Add (New INTEGER ());
}
Object [] ints = Li. toarray ();
String S = arrays. tostring (ints );
S = S. substring (1, S. Length ()-2 );
S = S. replaceall ("","");
A Ao = new ();
Int flag = integer. parseint (ARGs [0]);
AO. Sort (S, flag );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.