Java Implementation of Bubble sorting and selective sorting

Source: Internet
Author: User

1. The Bubble Sorting starts from the first one. Compared with the second one, the Bubble Sorting is large and the Bubble Sorting is small... Then, from the second one, put the big one behind the big one and put the small one on the front... Compare them in sequence, and put the largest one to the end. Then start from the beginning until the second to the second. In this way, the larger number is moved back every time, just like the bubble. So it is called Bubble sorting. Public static void main (String [] args) {int [] arr = {,}; int temp; for (int I = 0; I <arr. length-1; I ++) {for (int j = 0; j <arr. length-1-i; j ++) {if (arr [j]> arr [j + 1]) {temp = arr [j]; arr [j] = arr [j + 1]; arr [j + 1] = temp ;}}for (int I: arr) {System. out. print (I + "") ;}} 2. it is not stable to select sorting and select sorting. It is generally not recommended. Start from the first number and start from the Second, Third,... the last ratio. Put the small one on the first one each time. The second step is from the first to the third. Put the smallest value in the second one. Compare them in sequence. For (int I = 0; I <arr. length-1; I ++) {for (int j = I + 1; j <arr. length; j ++) {if (arr [I]> arr [j]) {temp = arr [I]; arr [I] = arr [j]; arr [j] = temp ;}}

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.