The Artima Developer Community
Sponsored Link

Java Buzz Forum
Bubble sort algorithm in java with example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Bubble sort algorithm in java with example Posted: Dec 28, 2015 6:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Bubble sort algorithm in java with example
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
 Java Program to sort array using bubble sort

  1. package com.instaceofjava; 

  2. public class BubbleSortExample{
  3.   
  4. int[] array={4,2,5,6,9,1};
  5.  
  6. int n = array.length;
  7. int k;
  8.  
  9. for (int m = n; m>= 0; m--) {
  10.  
  11. for (int j = 0; j < n-1; j++) {
  12.  
  13.    k = j + 1;
  14.  
  15.  if (array[j] > array[k]) {
  16.  
  17.        int temp;
  18.        temp = array[j];
  19.        array[j] = array[k];
  20.        array[k] = temp;
  21.  
  22. }
  23. }
  24.            
  25. for (int x = 0; x < array.length; x++) {
  26.  
  27. System.out.print(array[x] + ", ");
  28.  
  29.  }
  30.  
  31. System.out.println();
  32. }  
  33.  
  34. }
  35.  
  36. }



Output:

  1. 2, 4, 5, 6, 1, 9, 
  2. 2, 4, 5, 1, 6, 9, 
  3. 2, 4, 1, 5, 6, 9, 
  4. 2, 1, 4, 5, 6, 9, 
  5. 1, 2, 4, 5, 6, 9, 
  6. 1, 2, 4, 5, 6, 9, 
  7. 1, 2, 4, 5, 6, 9,

Read: Bubble sort algorithm in java with example

Topic: Producer Consumer Solution using BlockingQueue in Java Previous Topic   Next Topic Topic: Ruby on Rails takes on Node.js with WebSocket support, API mode

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use