Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //selection sort
- #include<bits/stdc++.h>
- using namespace std;
- void sup(int *x,int *y)
- {
- int te=*x;
- *x=*y;
- *y=te;
- }
- void selecso(int a[],int n)
- {
- int mi,i,j;
- for(i=0;i<n;i++)
- {int mi=i;
- for(j=i+1;j<n;j++)
- {
- if(a[j]<a[mi])
- mi=j;
- }
- sup(&a[mi],&a[i]);
- }
- }
- int main()
- {
- int n,i,j;
- cout<<"enter the number u want to input "<<endl;
- cin>>n;
- int a[n];
- for(i=0;i<n;i++)
- cin>>a[i];
- selecso(a,n);
- for(i=0;i<n;i++)
- cout<<a[i]<<" ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement