Demo entry 6754414

c++

   

Submitted by anonymous on Jul 12, 2018 at 04:58
Language: C++. Code size: 353 Bytes.

    void selectionSort(vector<int>& nums) {
        if(nums.size() <= 1)    return;

        for(int i=0; i<nums.size()-1; ++i) {
            int minIndex = i;
            for(int j=i+1; j<nums.size(); ++j) {
                if(nums[j] < nums[minIndex])    minIndex = j;
            }
            swap(nums[i], nums[minIndex]);
        }
    }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).