Add all 23 GoF design pattern implementations (2026-06-13)
This commit is contained in:
12
03-behavioral/strategy/BubbleSort.java
Normal file
12
03-behavioral/strategy/BubbleSort.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package strategy;
|
||||
|
||||
public class BubbleSort implements SortStrategy {
|
||||
@Override
|
||||
public void sort(int[] data) {
|
||||
System.out.println(" [BubbleSort] O(n²) — small arrays only");
|
||||
for (int i = 0; i < data.length - 1; i++)
|
||||
for (int j = 0; j < data.length - 1 - i; j++)
|
||||
if (data[j] > data[j + 1]) { int t = data[j]; data[j] = data[j+1]; data[j+1] = t; }
|
||||
}
|
||||
@Override public String getName() { return "BubbleSort"; }
|
||||
}
|
||||
Reference in New Issue
Block a user