Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*sa se scrie o functie ce foloseste metoda DEI si afla de cate ori apare nr x intr-un vector sortat crescator*/
- #include <iostream>
- using namespace std;
- int countx(int v[], int p, int q, int x) {
- if (p > q)
- return 0;
- int mid = (p + q) / 2;
- if (v[mid] == x)
- return countx(v, p, mid - 1, x) + countx(v, mid + 1, q, x) + 1;
- if (x < v[mid])
- return countx(v, p, mid - 1, x);
- return countx(v, mid + 1, q, x);
- }
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement