Skip to content
Open
Show file tree
Hide file tree
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
47 changes: 47 additions & 0 deletions bubble-sort/BubbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* @(#)BubbleSort.java 1.0.0 26/09/27
*
* Bubble Sort implementation for ascending integer arrays.
*
* Built using Vim
* OpenJDK Runtime Environment 21.0.12
*
*/


public class BubbleSort{

public static void main(String[]args){
int arr[] = {1,56,38,3, 0, 16, 74};
int i;
int j;
int k;
int l;
boolean flag;
k = 0;
l = 0;

for(i = 0; i < arr.length-1;i++){
flag = true;
for(j = 0; j < arr.length-1;j++){
if(arr[j]> arr[j+1]){
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
k++;
flag = false;
}
l++;

}
if(flag){
break;
}
}

for(i = 0; i<arr.length; i++){
System.out.println(arr[i]);
}

}
}
16 changes: 16 additions & 0 deletions bubble-sort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Bubble Sort

A simple Java implementation of the Bubble Sort algorithm.

## Description

Bubble Sort repeatedly compares adjacent elements and swaps them when they are in the wrong order.

This implementation sorts an integer array in ascending order.

## How to run

Compile:

```bash
javac BubbleSort.java
Loading