Skip to content

Instantly share code, notes, and snippets.

@veeara282
Created October 1, 2017 00:58
  • Select an option

Select an option

Revisions

  1. Aidan Fitzgerald created this gist Oct 1, 2017.
    16 changes: 16 additions & 0 deletions BitSort.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    import java.util.BitSet;

    public class BitSort {

    public BitSet sort(BitSet bits) {
    // Count the number of ones: O(n)
    int numOnes = bits.cardinality();

    // Overwrite the array with the ones first followed by the zeros
    bits.set(0, numOnes);
    bits.clear(numOnes, bits.size());

    return bits;
    }

    }