Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void selection(int arr[],int n)
- {
- for(int i=0; i<n; i++)
- {
- int small=i ;
- for(int j=i+1; j<n+1; j++)
- {
- if(arr[j]<arr[small])
- small=j;
- }
- if(small !=i)
- {
- int temp=arr[i];
- arr[i]=arr[small];
- arr[small]=temp;
- }
- }
- for(int i=0; i<n; i++)
- {
- cout<<arr[i]<<endl;
- }
- }
- int main()
- {
- int arr[]={1,6,3,9,13,7,19};
- selection(arr,7);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement