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
31 changes: 31 additions & 0 deletions Algorithms/Java/BurbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class BubbleSort {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be BubbleSort.java, not BurbleSort.java

public static void main(String[] args) {
int[] arr = {64, 34, 25, 12, 22, 11, 90};

bubbleSort(arr);

System.out.println("Sorted array:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}

static void bubbleSort(int arr[]) {
int n = arr.length;
boolean swapped;
for (int i = 0; i < n - 1; i++) {
swapped = false;
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = true;
}
}
if (!swapped) {
break;
}
}
}
}
1 change: 0 additions & 1 deletion Algorithms/Java/test

This file was deleted.

16 changes: 16 additions & 0 deletions Algorithms/Python/BubbleSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def burble_sort(arr):
n = len(arr)

for i in range(n):
swapped = False

for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j] # Swap elements
swapped = True
if not swapped:
break
arr = [64, 34, 25, 12, 22, 11, 90]
bubble_sort(arr)
print("Sorted array:")
print(arr)
1 change: 0 additions & 1 deletion Algorithms/Python/test

This file was deleted.