Horje
selection sort Code Example
selection sort
#include <bits/stdc++.h>

using namespace std; 

void selectionSort(int arr[], int n){
    int i,j,min;
    
    for(i=0;i<n-1;i++){
        min = i;
        for(j=i+1;j<n;j++){
            if(arr[j] < arr[min]){
                min = j;
            }
        }
        if(min != i){
            swap(arr[i],arr[min]);
        }
    }
}

int main()  
{  
    int arr[] = { 1,4,2,5,333,3,5,7777,4,4,3,22,1,4,3,666,4,6,8,999,4,3,5,32 };  
    int n = sizeof(arr) / sizeof(arr[0]);  

    selectionSort(arr, n);  

    for(int i = 0; i < n; i++){
        cout << arr[i] << " ";
    }

    return 0;  
}  
selection sort
// C algorithm for SelectionSort

void selectionSort(int arr[], int n)
{
	for(int i = 0; i < n-1; i++)
	{
		int min = i;
        
		for(int j = i+1; j < n; j++)
		{
			if(arr[j] < arr[min])
            	min = j;
		}
        
		if(min != i)
		{
        	// Swap
			int temp = arr[i];
			arr[i] = arr[min];
			arr[min] = temp;
		}
	}
}
Selection Sort
import numpy as np

def selection_sort(x):
    for i in range(len(x)):
        swap = i + np.argmin(x[i:])
        (x[i], x[swap]) = (x[swap], x[i])
    return x
Selection Sort
# Selection Sort
A = [5, 2, 4, 6, 1, 3]
for i in range(len(A)):
    minimum = i
    for j in range(i, len(A)):
        if A[j] < A[minimum]:
            minimum = j
    if i != minimum:
        A[minimum], A[i] = A[i], A[minimum]
selection sort
def ssort(lst):
    for i in range(len(lst)):
        for j in range(i+1,len(lst)):
            if lst[i]>lst[j]:lst[j],lst[i]=lst[i],lst[j]
    return lst
if __name__=='__main__':
    lst=[int(i) for i in input('Enter the Numbers: ').split()]
    print(ssort(lst))
Selection Sort
#include<bits/stdc++.h>
using namespace std;
void print(int arr[], int n)
{
    for(int i=0;i<n;i++)
        cout<<arr[i]<<" ";
    cout<<endl;
}
void selectionSort(int arr[], int n)
{
    int i,j,min_in;
    for(i=0;i<n;i++)
    {
        min_in = i;
        for(j=i+1;j<n;j++)
            if (arr[j] < arr[min_in])
                min_in = j;
        swap(arr[i],arr[min_in]);
    }
}
int main(int argv, char* argc[])
{
    int arr[] = {5,4,10,1,6,2};
    int i,j,n,temp;
    n = sizeof(arr)/sizeof(int);
    cout<<"Unsorted Array :";
    print(arr,n);
    selectionSort(arr,n);
    cout<<"Sorted Array :";
    print(arr,n);
    return(0);
}
Source: favtutor.com
selection sort
// Easy-peasy
#include<iostream>
#include<algorithm>
using namespace std;

void selectionSort(vector<int> &arr) {
    for(int i = 0; i < arr.size() - 1; ++i) {
		for(int j = i + 1; j < arr.size(); ++j) {
			if(arr[j] < arr[i]) swap(arr[i], arr[j]);
		}
    }
}

int main() {
    vector<int> arr = {3,7,12,99,231,4,-6,-77,10};
    selectionSort(arr);
    for(auto it : arr) cout << it << " ";
    return 0;
}
Selection Sort
x = np.array([2, 1, 4, 3, 5])
selection_sort(x)
Selection Sort
array([1, 2, 3, 4, 5])




Cpp

Related
c++ expected an identifier Code Example c++ expected an identifier Code Example
c++ map values range Code Example c++ map values range Code Example
getline trong c++ Code Example getline trong c++ Code Example
7 9 C:\Users\Aliyah\Documents\shut up.cpp [Error] expected unqualified-id before string constant Code Example 7 9 C:\Users\Aliyah\Documents\shut up.cpp [Error] expected unqualified-id before string constant Code Example
get rest of a stringstream c++ Code Example get rest of a stringstream c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10