Selection Sort in array by using C++ in DSA

Selection Sort in array by using C++ in DSA

#include <iostream>
using namespace std;
void selec_sort(int arr[], int n){
for(int i=0; i<n-1; i++){
for(int j=i+1; j<n; j++){
if(arr[j]<arr[i]){
int temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
}
void display(int arr[], int n){
for(int i=0; i<n; i++){
cout<<arr[i]<<" ";
}
}
int main() {
int arr[]={12,45,80,5,19,8};
int n=sizeof(arr)/sizeof(arr[0]);
selec_sort(arr, n);
display(arr,n);
return 0;

} 

Post a Comment

0 Comments