From a2e057c7e46a33ab35e361805b7f43524c819ffa Mon Sep 17 00:00:00 2001 From: ASIF ELAHI <149480370+asifelahii@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:57:44 +0600 Subject: [PATCH] selection_sort Implementation of selection_sort algorithm using c++ to sort an array. --- selection_sort/selection_sort_cpp.cpp | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 selection_sort/selection_sort_cpp.cpp diff --git a/selection_sort/selection_sort_cpp.cpp b/selection_sort/selection_sort_cpp.cpp new file mode 100644 index 0000000..f02f2e3 --- /dev/null +++ b/selection_sort/selection_sort_cpp.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; +/* + #Selection sort algorithm. + -Find the minimum element in unsorted array & swap it with the element at beginning.[1] + -repeate [1] until the array is sorted. + + paremeter: + -n = to recieve array size. + -arr[] = to recieve the array[] +*/ +void selection_sort(int n,long long arr[]) +{ + double temp; + /*i is iterating from 1st index (i=0) to 2nd last index (n-1) of the array*/ + for(int i=0; i> n;//taking input for n + long long arr[n];//declaring & initializing arr[n] + + + //Taking input for arr[n] + for(i=0; i> arr[i]; + } + + /* + passing arguments (n,arr): + -n = passing size of arr[n] + -arr = passing all the elements of arr[n] + */ + selection_sort(n,arr);//calling selection sort function & passing arguments. + + + /*printing sorted arr[n]*/ + for(i=0; i