Different kinds of sorting programs in Java
- Make sure JDK is installed.
- After downloading, go into the directory of the sorting program you'd like to use
- Assuming you want to use bubble sort, while in the directory in CLI, type:
- javac BubbleSort.java
- java BubbleSort
- Follow the instructions.
- Known as the simplest sorting program
- Array is traversed from first element to last element
- Current element is compared with next element, if the current element is greater than next element, it is swapped
- Divides the array into two
- Sorted array
- Unsorted array
- Checks the entire array for the minimum element and places it at the beginning of the sorted list and so on
- Only good for smaller arrays, because it takes lots of time
- Transfers one element at a time to the right position