Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void selection_r(int n, int a[], int i)
- {
- if(n>1)
- {
- int p=1,max=a[1];
- if(i<n)
- {
- if(a[i]>max)
- {
- max=a[i]; p=i;
- }
- selection_r(n,a,i+1);
- } else {
- swap(a[p],a[n]);
- selection_r(n-1,a,1);
- }
- }
- }
- int main()
- {
- int n,a[100];
- cout<<"n="; cin>>n;
- cout<<"Introduceti elementele vectorului: "<<endl;
- for(int i=1;i<=n;i++)
- cin>>a[i];
- selection_r(n,a,1);
- cout<<"Sirul sortat este: ";
- for(int i=1;i<=n;i++)
- cout<<a[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement