Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void selection(int arr[], int S){
- int select,minValue,minIndex,i;
- for(select=0; select<S-1; select++){
- minIndex=select;
- minValue=arr[select];
- for(i=select+1; i<S;i++){
- if(arr[i]<minValue){
- minValue=arr[i];
- minIndex=i;
- }
- }
- arr[minIndex]=arr[select];
- arr[select]=minValue;
- }
- }
- int main(){
- int i,n;
- cout<<"enter Array size"<<endl;
- cin>>n;
- int a[n];
- std::cout << "Enter array numbers" << std::endl;
- for(i=0; i<n;i++){
- cin>>a[i];
- }
- selection(a,n);
- for(i=0; i<n;i++){
- cout<<" "<<a[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement