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 understand Bubble sorting algorithm in Java Array

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article analyzes "how to understand the bubble sorting algorithm in Java array". The content is detailed and easy to understand. Friends who are interested in "how to understand the bubble sorting algorithm in the Java array" can follow the editor's train of thought to read it slowly and deeply. I hope it will be helpful to everyone after reading. Let's follow the editor to learn more about how to understand the bubble sorting algorithm in the Java array.

/ * * Bubble algorithm: the score arrays will be sorted from small to large output idea: the first pass sort 1. Compare the n elements in the array, starting with the first element, with the following elements. If the previous data is larger than the later data, and the two swap positions are until a loop is complete, then the largest data in the array will be ranked at the last position in the array. The order of the first round is 3. And so on, the remaining unsorted nmuri elements are similar to the process of 1Power2 again, so that until the end of the loop n times, the elements in the array are sorted from small to large. Note: you only need to go through nmai sorting once * / public class BubbleSort {public static void sort (int [] arrays) {/ / the first cycle control nmai sorting for (int I = 0; I)

< arrays.length - 1; i++) { //第二个循环控制每次要比较的元素个数n-1 for (int j = 0; j < arrays.length - i - 1; j++) { if (arrays[j] >

Arrays [j + 1]) {int flag = arrays [j]; arrays [j] = arrays [j + 1]; arrays [j + 1] = flag }} public static void main (String [] args) {/ / definition and initialization of one-dimensional array int [] scores = {90, 70, 50, 80, 60, 85}; sort (scores) / / output sorted scores for (int I = 0; I < scores.length; iTunes +) {System.out.print (score [I] + ",");}} about how to understand the bubble sorting algorithm in the Java array. I hope the above content can improve everyone. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

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

Development

Wechat

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

12
Report