冒泡排序程序java_冒泡排序Java程序

冒泡排序程序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]+" "); 
 }
}
Bubble Sort Java Program

翻译自: https://www.thecrazyprogrammer.com/2015/04/bubble-sort-java-program.html

冒泡排序程序java

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值