Class ListSortAndSearch
java.lang.Object
|
+--ListSortAndSearch
- public class ListSortAndSearch
- extends java.lang.Object
Class ListSortAndSearch contains sorting and searching algorithms for
array-based lists. The sorting algorithm is an O(N2) bubble
sort. Two searching algorithms are provided -- an O(N) linear search and
and O(log N) binary search.
Method Summary |
int |
binarySearch(java.lang.Object[] list,
java.lang.Object element)
Perform an iterative binary search of the given list for the given
element. |
int |
linearSearch(java.lang.Object[] list,
java.lang.Object element)
Perform an iterative linear search of the given list for the given
element. |
void |
sort(java.lang.Object[] list)
Perform a bubble sort on the given list. |
java.lang.String |
toString(java.lang.Object[] list)
Make a space-delimited string out of the elements of an array-based
list. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ListSortAndSearch
public ListSortAndSearch()
sort
public void sort(java.lang.Object[] list)
- Perform a bubble sort on the given list.
linearSearch
public int linearSearch(java.lang.Object[] list,
java.lang.Object element)
- Perform an iterative linear search of the given list for the given
element. Assume the list is not null. Return the index position of the
first occurrence of the element if found, -1 otherwise.
binarySearch
public int binarySearch(java.lang.Object[] list,
java.lang.Object element)
- Perform an iterative binary search of the given list for the given
element. Assume the list is not null. Return the index position of the
first occurrence of the element if found, -1 otherwise.
toString
public java.lang.String toString(java.lang.Object[] list)
- Make a space-delimited string out of the elements of an array-based
list.