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