T
- should implement the Comparable interfacepublic class BubbleSort<T extends java.lang.Comparable<T>> extends SortAlgorithm
Constructor and Description |
---|
BubbleSort(java.util.ArrayList<T> data)
constructor for creating a bubble sort instance via passing an ArrayList of data
|
BubbleSort(T[] dataArray)
constructor for creating a bubble sort instance via passing an array of data
|
Modifier and Type | Method and Description |
---|---|
private boolean |
checkBounds(int left,
int right)
this method checks bounds for left and right indexes given to sort method
|
java.util.ArrayList<T> |
getData() |
void |
setData(java.util.ArrayList<T> data) |
void |
sort()
this method sorts the data array using bubble sort algorithm
it doesn't return anything.To access the sorted data, call the getData method.
|
void |
sort(int left,
int right)
this method sorts a part of the array indicated by left and right index
|
swap, swap
public BubbleSort(T[] dataArray)
dataArray
- an array of data of type Tpublic BubbleSort(java.util.ArrayList<T> data)
data
- an ArrayList of data of type Tpublic void setData(java.util.ArrayList<T> data)
data
- a new ArrayList that replaces the existing onepublic void sort()
public void sort(int left, int right)
left
- is the starting of the partition to sort. It is inclusiveright
- is the end of the partition to sort. It is exclusive
it doesn't return anything.To access the sorted data, call the getData method.private boolean checkBounds(int left, int right)
public java.util.ArrayList<T> getData()