TestBubbleSort

TestBubbleSort - } public static void bubbleSort(int list,...

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

View Full Document Right Arrow Icon
public class TestBubbleSort { public static void main(String[] args) { int list[] = {2, 56, 34, 25, 73, 46, 89, 10, 5, 16}; //Line 1 int i; //Line 2 bubbleSort(list, 10); //Line 3 System.out.println("After sorting, the " + "list elements are:"); //Line 4 for (i = 0; i < 10; i++) //Line 5 System.out.print(list[i] + " "); //Line 6 System.out.println(); //Line 7
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } public static void bubbleSort(int list, int listLength) { int temp; int counter, index; for (counter = 0; counter &lt; listLength - 1; counter++) { for (index = 0; index &lt; listLength - 1 - counter; index++) if (list[index] &gt; list[index + 1]) { temp = list[index]; list[index] = list[index + 1]; list[index + 1] = temp; } } } }...
View Full Document

Ask a homework question - tutors are online