diff --git a/selection-sort.cpp b/selection-sort.cpp new file mode 100644 index 0000000..03eaa48 --- /dev/null +++ b/selection-sort.cpp @@ -0,0 +1,44 @@ +#include +using namespace std; +void selectionsort(int [], int); +void swap(int*, int*); +void getArray(int [], int); +int main() //Driver code +{ + int arr[] = {-2, 6, 28, 13, 16, 11}; + int n = 6; + selectionsort(arr, n); + cout<<"Sorted Array:\n"; + getArray(arr, n); + return 0; +} +void swap(int *x, int *y) //Function to swap the elements +{ + int temp; + temp = *x; + *x = *y; + *y = temp; +} +void selectionsort(int arr1[], int sz) //Selection sort function +{ + int i, j, small; + for (i = 0; i