Java data structure bubble sort implementation code _java

Source: Internet
Author: User

The basic idea of bubbling (Bubble sort) is: consider arrays to be sorted from top to bottom, with smaller keywords as lighter, larger keywords as heavier, smaller keyword values as bubbles in the water to float, larger keywords like rocks in the water to sink. , the sort ends when the bubbles are floating in the appropriate position.

Algorithm performance analysis

(1) time complex element. The total must be the number of 3/2 (n-1) *n

(2) The complexity of the space. Only one auxiliary unit with space complexity of O (1)

(3) The stability of the algorithm. Bubble sort is a stable sort algorithm

* *
 Kiss_my_love *
 2012/8/20 *
 bubble sort
 **/public
 static object[] Bubblesort (Object []sort) {
  for (int i=1;i<sort.length;i++) {for
 (int j=0;j<sort.length-i;j++) {
   if ((integer) sort[j]> (integer) Sort[j+1]) {
  Object temp=sort[j];
  SORT[J]=SORT[J+1];     
  Sort[j+1]=temp
   }
 }} return sort; 
 }

 

Thank you for reading this article, I hope to help you, thank you for your support of this site!

Related Article

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.