Skip to content

Latest commit

 

History

History
57 lines (43 loc) · 1.66 KB

README.md

File metadata and controls

57 lines (43 loc) · 1.66 KB

Sort Algorithms

List

Usage of the Sort Algorithms

public static void main(String[] args) {
		
	int arr[] = {5,3,8,2,1}; // This is the list of numbers to be sorted.
		
	String list = "";
	for (int i = 0; i < arr.length; i++) 
		list = list + " " + arr[i];
        
	System.out.println("Unsorted List: " + list); // Here you output the unsorted list in the console.
		
	ExampleSort sort = new ExampleSort(arr); // Here you give the algorithm the list.
	sort.sort(); // Here you sort the list.
		
	System.out.println("Sorted List: " + sort.get()); // Here you output the sorted list in the console.
}

Example with Bubble Sort

As an Example i will use Bubble Sort Algorithm.

public static void main(String[] args) {
		
	int arr[] = {5,3,8,2,1};
		
	String list = "";
        
	for (int i = 0; i < arr.length; i++)
		list = list + " " + arr[i];
        
	System.out.println("Unsorted List: " + list);
		
	BubbleSort sort = new BubbleSort(arr);
	sort.sort();
		
	System.out.println("Sorted List: " + sort.get());
}

The output in the console is

Unsorted List:  5 3 8 2 1
Sorted List:  1 2 3 5 8