Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Selection sort
- // Date : 17.10.19
- #include<iostream>
- using namespace std;
- void selectionSort(int arr[], int n){
- int select = 0;
- for(int i = 0; i < n-1; i++){
- for(int j = i + 1; j < n; j++){
- if(arr[j] < arr[i]) { select = j; }
- }
- int temp = arr[i];
- arr[i] = arr[select];
- arr[select] = temp;
- }
- }
- int main(){
- int n;
- cout << "Enter the range of array: "; cin >> n;
- int arr[n], i;
- cout << "Enter the element of array: ";
- for(i = 0; i < n; i++){
- cin >> arr[i];
- }
- selectionSort(arr, n);
- cout << "The array after sorting: ";
- for(i = 0; i < n; i++){
- cout << arr[i] << ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement