Advertisement
STANAANDREY

12/10/2020clasa

Oct 12th, 2020 (edited)
2,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. /*sa se scrie o functie ce foloseste metoda DEI si afla de cate ori apare nr x intr-un vector sortat crescator*/
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int countx(int v[], int p, int q, int x) {
  6.     if (p > q)
  7.         return 0;
  8.     int mid = (p + q) / 2;
  9.     if (v[mid] == x)
  10.         return countx(v, p, mid - 1, x) + countx(v, mid + 1, q, x) + 1;
  11.     if (x < v[mid])
  12.         return countx(v, p, mid - 1, x);
  13.     return countx(v, mid + 1, q, x);
  14. }
  15.  
  16. int main() {
  17.     return 0;
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement