Selection sort in c++ with OOPS

PHOTO EMBED

Wed Apr 12 2023 14:53:08 GMT+0000 (Coordinated Universal Time)

Saved by @ronin_78 #c++

#include <iostream>
#include <vector>
using namespace std;

class selectionsort{
    private:
    int a[100];
    int n;

    public:

    selectionsort(int arr[], int size){
        n = size;
        int imin, temp;
        
        for (int i=0; i < n; i++) {
            a[i] = arr[i];
        }
       for(int i = 0; i<n-1; i++) {
          imin = i;   
          for(int j = i+1; j<n; j++)
             if(a[j] < a[imin])
                imin = j;
             temp = a[i];
             a[i] = a[imin];
             a[imin] = temp;
       }
    }
    
    void display() {
        cout << "Sorted Array: ";
        for (int i = 0; i < n; i++) {
            cout << a[i] << " ";
        }
        cout << endl;
    }
};

int main() {
    int size;
    
    cout << "Enter the size of the 1-d array: ";
    cin >> size;
    
    int arr[size];
    
    cout << "Enter all the elements separated with spaces\n";
    for(int i=0; i<size; i++){
        cin>>arr[i];
    }
    
    
    selectionsort ss(arr, size);
    ss.display();

    return 0;
}
content_copyCOPY