Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions Sorts/BubbleSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ class BubbleSort
*/
public static void main(String[] args)
{
int array[]=new int[6];
int size = 6;
int array[]=new int[size];
boolean swap;
int last = size - 1;
Scanner input=new Scanner(System.in);


//Input
System.out.println("Enter any 6 Numbers for Unsorted Array : ");
Expand All @@ -27,18 +31,22 @@ public static void main(String[] args)
}

//Sorting
for(int i=0; i<5; i++)
{
for(int j=i+1; j<6; j++)
{
if(array[j]>array[i])
{
int temp=array[j];
array[j]=array[i];
array[i]=temp;
}
}
}
do
{
swap = false;
for (int count = 0; count < last; count++)
{
if (array[count] > array[count + 1])
{
int temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
}

last--;
} while (swap);

//Output
for(int i=0; i<6; i++)
Expand Down