Advertisement
backlog

secection sort ,mine

Apr 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. //selection sort
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. void sup(int *x,int *y)
  5. {
  6.     int te=*x;
  7.     *x=*y;
  8.     *y=te;
  9. }
  10. void selecso(int a[],int n)
  11. {
  12.     int mi,i,j;
  13.        for(i=0;i<n;i++)
  14.         {int mi=i;
  15.           for(j=i+1;j<n;j++)
  16.           {
  17.               if(a[j]<a[mi])
  18.                 mi=j;
  19.  
  20.           }
  21.            sup(&a[mi],&a[i]);
  22. }
  23. }
  24. int main()
  25. {
  26.     int n,i,j;
  27.     cout<<"enter the number u want to input "<<endl;
  28.     cin>>n;
  29.     int a[n];
  30.     for(i=0;i<n;i++)
  31.         cin>>a[i];
  32.  
  33.     selecso(a,n);
  34.  
  35.  
  36.       for(i=0;i<n;i++)
  37.         cout<<a[i]<<" ";
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement