Sorting

Selection sort-

it is a O(n^2) technique to sort an array in ascending order.

Working: We take two pointers that traverse through the array.

Pointer 1 : slow - runs n times

Pointer 2: fast - runs [(n(n+1))/2] times.

pointer 2 find the element containing minimum number and then if it is smaller than pointer 1 then it swaps the value of pointer elements.

same thing is repeated till pointer 1 reaches at index [n-2 ]

#include <bits/stdc++.h>
using namespace std;
    void funcc(vector<int>& nums,int n ) {

        for(int i =0;i<n-1;i++){
            int j = n-1;
           // cout<<nums[i];
            while(i<j){
                //cout<<nums[j]<<'\n';
                if(nums[i]>nums[j]){
                    int temp = nums[i];
                    nums[i]=nums[j];
                    nums[j]=temp;
                }
                j--;
            }
            //index [i]now have the minimun element
            cout<<nums[i];
        }
       for(auto it:nums){
            cout<<it<<" ";
        }
    }
int main(){
    vector<int >nums;
    nums = {0,2,12,3,0};
    int n  =  nums.size();

    funcc(nums,n);



return 8;
}