Bubble - for(int j=0 j<i j if(arrayToSort[j>...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// The "Bubble" class. public class Bubble { public static void main (String[] args) { int numbers [] = new int [5]; numbers[0] = 3; numbers [1] = 2; numbers [2] = 1; numbers [3] = 5; numbers [4] = 4; n bubbleSort (numbers);// Place your code here } // main method public static void bubbleSort (int[] arrayToSort){ int temp; for (int i = arrayToSort.length-1; i>0; i--){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for (int j=0; j<i; j++){ if (arrayToSort[j] > arrayToSort[j+1]){ temp = arrayToSort[j]; arrayToSort[j] = arrayToSort[j+1]; arrayToSort[j+1] = temp; for (int k = 0 ; k<arrayToSort.length; k++) System.out.print (arrayToSort[k]+ " "); System.out.println(); } } } } } // Bubble class...
View Full Document

This note was uploaded on 12/01/2010 for the course APPLIED SC 142 taught by Professor Professorstansimmons during the Winter '10 term at Queens University.

Ask a homework question - tutors are online