Java Sorting-java sorting algorithms bubble sort code - Java Sorting-java sorting algorithms bubble sort code

bubble sort code

The bubble sort algorithm for an integer array class with Java language is presented below. The
sorting algorithm applies the private method swap in the operation.
public void bubbleSort()
{
int i,j;
for (i=aSize; i>1; i--)
for(j=0;j if(array[j] > array[j+1])
swap(j,j+1);
}

private void swap(int i, int j)
{
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}

0 comments:

Post a Comment