-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorting.java
More file actions
29 lines (18 loc) · 827 Bytes
/
Copy pathSorting.java
File metadata and controls
29 lines (18 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package DesignPattern.Strategy;
import java.util.Arrays;
import DesignPattern.Strategy.Context.SortingContext;
import DesignPattern.Strategy.Strategies.BubbleSortStrategy;
import DesignPattern.Strategy.Strategies.QuickSortStrategy;
public class Sorting {
public static void main(String[] args) {
int[] arr = {4, 16, 31, 5, 4, 17, 1, 10, 15, 3, 16, 6, 7, 2, 2, 1, 5, 13, 17, 14, 4, 0};
int[] arr2 = {4, 16, 31, 5, 4, 17, 1, 10, 15, 3, 16, 6, 7, 2, 2, 1, 5, 13, 17, 14, 4, 0};
SortingContext sortingContext = new SortingContext();
sortingContext.setSortingStrategy(new BubbleSortStrategy());
sortingContext.doSort(arr);
System.out.println(Arrays.toString(arr));
sortingContext.setSortingStrategy(new QuickSortStrategy());
sortingContext.doSort(arr2);
System.out.println(Arrays.toString(arr2));
}
}