Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Bubble sorting in java

2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article "java how to achieve bubble sorting" in addition to programmers, most people do not understand, today, in order to make you better understand "java how to achieve bubble sorting", summed up the following content, with a certain reference value, the detailed steps are clear, the details are handled properly, I hope you can get something through this article, let's take a look at the specific content.

Bubbling sorting is realized by two-layer nesting loops, the outer loop data compare the number of rounds, the inner loop control the number of times of each round, each round in turn to reduce the number of times of comparison, and finally achieve sorting.

Public static void main (String [] args) {/ * Bubble sorting is implemented by two-layer nested loops, the outer loop compares the number of rounds, the inner loop controls the number of times of comparison in each round, and each round reduces the number of comparisons in turn, and finally realizes the sorting * / out-of-order array int [] arr = {9pje 3je 2je 10je 4e 6}. / / the number of outer control comparison wheels for (int I = 0; I

< arr.length; i++) { //内层循环控制每轮对比次数,每一轮依次减少一次对比次数,减1是因为数组最末尾数字无需对比且不减少1会出现数组下标越界 for(int j = 0; j < arr.length - i -1; j ++){ //升序排序(从小到大):如果J下标数字大于后面数字则交换位置,将大的数字往后排,否则保持不动 //降序排序(从大到小):如果J下标数字小于后面数字则交换位置,将小的数字往后排,否则保持不动 if (arr[j] >

Arr [jacks 1]) {/ / defines temporary variables and swaps digital locations. Int temp = arr [j]; arr [j] = arr [juni1]; arr [juni1] = temp;} / / print the sort result for (int i:arr) {System.out.println (I);}} what are the advantages of Java. Simple, as long as understand the basic concepts, you can write applications suitable for a variety of situations; 2. Object oriented; 3. Distributed, Java is a network-oriented language; 4. Robust, java provides automatic garbage collection for memory management to prevent programmers from making mistakes when managing memory. ; 5. Security, Java used in the network and distributed environment must prevent the invasion of viruses. 6. Architecturally neutral, as long as the Java runtime system is installed, it can run on any processor. 7. Portability, Java can be easily ported to different machines on the network. 8. Interpretation execution, Java interpreter directly interprets and executes Java bytecode.

Thank you for your reading. I hope you have a certain understanding of the key issue of "how to achieve bubbling sorting in java". The specific usage needs to be understood by everyone through hands-on experiments. Try it quickly. If you want to read more articles about relevant knowledge points, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report