Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int trova_minimo(int v[], int sx, int dx)
- {
- int min_sx=-1, min_dx = -1;
- if (sx==dx) //un elemento solo
- {
- return v[sx];
- }
- else
- if (sx + 1 == dx ) //due elementi
- {
- if (v[sx]<v[dx])
- return v[sx];
- else
- return v[dx];
- }
- else
- {
- int mediano = sx +(dx - sx)/2;
- //cout << sx << " " << mediano << endl;
- min_sx = trova_minimo(v, sx, mediano);
- //cout << mediano+1 << " " << dx << endl;
- min_dx = trova_minimo(v, mediano+1, dx);
- }
- if (min_sx<min_dx)
- return min_sx;
- else
- return min_dx;
- }
- int main()
- {
- int v[]={18,6,2,20,1,40,7,8,12,60};
- cout << trova_minimo(v, 0, 9);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement