Skip to content

Instantly share code, notes, and snippets.

@itsknk
Created October 10, 2020 16:25
Show Gist options
  • Save itsknk/5c182ce624d398aa118c1c2b7e979cf9 to your computer and use it in GitHub Desktop.
Save itsknk/5c182ce624d398aa118c1c2b7e979cf9 to your computer and use it in GitHub Desktop.
import java.util.*;
public class bubbleSort
{
public static void main(String args[])
{
int arr[] = { 2,8,5,3,9,4,1 };
for(int i=0; i<arr.length; i++)
{
for(int j=1; j<arr.length-i; j++)
{
if(arr[j-1] > arr[j])
{
int temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
}
}
for(int i=0; i<arr.length; i++)
{
System.out.print(arr[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment