冒泡排序程序java
Bubble sort in java is the simplest sorting technique. In bubble sort algorithm each element is compared to next adjacent element, if the next element is smaller, then it will be swapped by previous element. Although this technique is simple but it is too slow as compared to other
冒泡排序是最简单的排序技术。 在冒泡排序算法中,将每个元素与下一个相邻元素进行比较,如果下一个元素较小,则将被前一个元素交换。 尽管此技术很简单,但与其他
sorting techniques. Below I have shared the bubble sort java program. If you find anything missing or incorrect then please mention it in comment section. You can also ask your queries.
排序技术相比太慢了。 下面我分享了冒泡排序java程序。 如果您发现任何缺失或不正确的内容,请在评论部分中提及。 您也可以询问您的问题。
冒泡排序Java程序 (Bubble Sort Java Program)
import java.util.Scanner;
class BubbleSort
{
public static void main(String...s)
{
int a[]=new int[20],n,i,j,temp;
Scanner sc=new Scanner(System.in);
System.out.println("Enter how many elements:");
n=sc.nextInt();
System.out.println("nEnter elements of array:");
for(i=0;i<n;++i)
a[i]=sc.nextInt();
for(i=1;i<n;++i)
for(j=0;j<n-i;++j)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
System.out.println("nArray after bubble sort:");
for(i=0;i<n;++i)
System.out.print(a[i]+" ");
}
}
翻译自: https://www.thecrazyprogrammer.com/2015/04/bubble-sort-java-program.html
冒泡排序程序java
本文介绍了一种简单的排序技术——冒泡排序,并提供了一个用Java实现的冒泡排序程序示例。冒泡排序通过比较并交换相邻元素来对数组进行排序,虽然其简单直观,但在大数据集上效率较低。
11万+

被折叠的 条评论
为什么被折叠?



