visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: Java :: algorithm of simple java bubble sort


By: Bernard France  Date: 07/10/2005 10:33:14  English  Points: 20 Status: Answered
Quality : Excellent
I search for an algorithm of simple java bubble sort
By: VGR Date: 07/10/2005 10:34:12 English  Type : Answer
Hello 8-)

I suppose this PAQ will do it ;-)

It's exactly an algorithm and it's almost directly portable to Java, given it's in Pascal ;-)
By: spoonman Date: 24/05/2007 14:02:56 English  Type : Comment
Bubble sorts are an elementary way of sorting and for more complex lists they are probably not appropriate. Wikipedia has a nice breakdown on sorting algorithm's which you may want to look at. Examples of many of these algorithms can be found
here.

Below is how Sun suggests you do a bubble sort. This was taken from the link given above.


/* * @(#)BubbleSortAlgorithm.java 1.6 95/01/31 James Gosling * * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL purposes and without * fee is hereby granted provided that this copyright notice * appears in all copies. Please refer to the file "copyright.html" * for further important copyright and licensing information. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ /** * A bubble sort demonstration algorithm * SortAlgorithm.java, Thu Oct 27 10:32:35 1994 * * @author James Gosling * @version 1.6, 31 Jan 1995 * * Modified 23 Jun 1995 by Jason Harrison@cs.ubc.ca: * Algorithm completes early when no items have been swapped in the * last pass. */

class BubbleSort2Algorithm extends SortAlgorithm { void sort(int a[]) throws Exception { for (int i = a.length; --i>=0; ) { boolean flipped = false; for (int j = 0; j<i; j++) { if (stopRequested) { return; } if (a[j] > a[j+1]) { int T = a[j]; a[j] = a[j+1]; a[j+1] = T; flipped = true; } pause(i,j); } if (!flipped) { return; } } } }



Do register to be able to answer

EContact
browser fav
page generated in 93.503000 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page