arraybub{ [] (max) { = [max]= } (value) { [] = value++} () { (j=j<j++) { system. Print ([j]+) System: println ()} } () { Outinlong tem (out = -out>out--) { (in = in<outin++) { ([in] > [in+]) { tem = [in+][in+] = [in][in] = tem} } } }}
Bubblesort {(string[] args) {maxSize = Arraybub arr = Arraybub (maxSize) Arr.insert () Arr.insert () arr.inse RT () Arr.insert () Arr.insert () Arr.insert () Arr.insert () Arr.insert () Arr.insert () Arr.insert () Arr.insert () Arr.insert () Arr.insert () Arr.display () Arr.bubblesort () Arr.display ()} () {}}
First look at the above code, bubble sort core is: Bubblesort () method, for loop nesting, the outer layer of each row minus one, the inner contrast to the outer value of out.
The bubble sorting algorithm makes N (N-1)/2 comparisons, that is, O (n*n), which removes the minus and ignores the constant 2 to derive the secondary result.
This article is from the "Yao Sea" blog, please be sure to keep this source http://tl2011.blog.51cto.com/6006611/1884031
Bubbling ordering of Java data structures