Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vezi filmuletul: https://www.youtube.com/watch?v=hA5xtJFp8_c&feature=youtu.be
- #include <iostream>
- using namespace std;
- int cauta(int v[], int n, int x){
- int st=0;
- int dr=n-1;
- while(st<=dr)
- {
- int mid = (st+dr)/2;
- if (v[mid]==x) return mid;
- if (v[mid] < x) st = mid+1;
- else dr = mid-1;
- }
- return -1;
- }
- int main()
- {
- int sir[13] = {1,3,5,6,7,9,10,12,13,15,18,19,20};
- for(int i=1; i<=20; i++)
- cout << i << " - "<< cauta(sir, 13, i) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment