Fandom

Programmer's Wiki

Sorting

408pages on
this wiki
Add New Page
Talk0 Share

A sorting algorithm is an algorithm that orders a specific data structure, such as lists and trees.

A few sorting algorithms are:

ExamplesEdit

Java Edit

(built-in) To be able to sort objects of some arbitrary class you will need to provide a comparator to the sort method.

Array Edit

you need to import java.util.Arrays to sort arrays

import java.util.Arrays;

public class Sort {
    // define main method of this java code
    public static void main(String[] args){
    
        // declare an array named intArray for integer type values
        int[] intArray = {15,17,14,20};
        Arrays.sort(intArray);   
    }
}

List Edit

You need to import java.util.Collections to sort Lists

import java.util.Collections;

public class Sort {
    // define main method of this java code
    public static void main(String[] args){
    
        // declare an array named intArray for integer type values
        int[] intArray = {15,17,14,20};
        List list = Arrays.asList(intArray);

        Collections.sort(list)
    }
}
Sorting algorithms
Bubble sort - Insertion sort - Merge sort - Quicksort - Selection sort

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.