Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

selection sort c++

class Practice
{
public:
    void practice1(vector<int> &arr)
    {
        /* Selection sorting */

        int current_min_i = 0;

        for (int i = 0; i < arr.size() - 1; i++)
        {
            current_min_i = i;
            for (int j = i + 1; j < arr.size(); j++)
                if (arr[current_min_i] > arr[j])
                    current_min_i = j;

            swap(arr[i], arr[current_min_i]);
        }

        cout << "Displaying sorted array: ";
        for (int i : arr)
            cout << i << " ";
    }
};

int main()
{
    vector<int> arr{64, 25, 12, 22, 11};

    Practice op;
    op.practice1(arr); 
}
 
PREVIOUS NEXT
Tagged: #selection #sort
ADD COMMENT
Topic
Name
6+1 =