Demo entry 4797995

Billy sorter

   

Submitted by anonymous on May 18, 2016 at 12:41
Language: C++. Code size: 458 Bytes.

class billy_sorter {
public:
    std::vector<int> v;
    billy_sorter(std::vector<int> v): v(v) { }
    void sort() {
        bool sorted = false;
        std::size_t n = v.size();
        while (!sorted) {
            sorted = true;
            for (std::size_t i = 1; i < n; i++)
                if (v[i - 1] > v[i]) {
                    sorted = false;
                    std::swap(v[i - 1], v[i]);
                }
        }
    }
};

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).