Selection Sort


source code

Java Code

Warning: Only the algorithm is displayed on this page.
Download the source code for a compilable/runnable test, or go here for the complete library of sorting algorithms.
package sorts;

 * Created by Stijn Strickx on May 21, 2008
 * Copyright 2008 Stijn Strickx, All rights reserved

 * Selection sort algorithm
 * Time Complexity: O(n*n)
 * Memory Complexity: O(1)
 * Stable: yes
 * Note: Other implementations of the selection sort algorithm might not be stable.

public class SelectionSort extends Sorter{

    public <T extends Comparable<? super T>> void sort(T[] a) {
        for(int i = 0; i < a.length; i++){
            int min = i;
            for(int j = i+1; j

Home | Code | Learn
© 2007-2008 ProgLogic, all rights reserved. | is created by Stijn Strickx. | e-mail