Mansour
Mansour
Mansour
#include <vector>
if (nums[mid] == target)
return mid;
else if (nums[mid] < target)
left = mid + 1;
else
right = mid - 1;
}
return false;
}
#include <iostream>
#include <vector>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
int main() {
// Example of vector
vector<int> v = {1, 2, 3, 4, 5};
// Example of map
map<string, int> m;
m["apple"] = 3;
m["banana"] = 2;
// Example of set
set<int> s = {5, 2, 8, 1};
// Example of queue
queue<int> q;
q.push(1);
q.push(2);
// Example of stack
stack<int> st;
st.push(1);
st.push(2);
return 0;
}
#include <queue>
priority_queue<int> pq; // Max heap
priority_queue<int, vector<int>, greater<int>> minHeap; // Min heap
#include <deque>
deque<int> dq;
dq.push_back(1);
dq.push_front(2);
###############
int position = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
Here’s what each part does:
upper_bound(a.begin(), a.end(), b[i]): This function searches for the first element in the range [a.begin(), a
.end()) that is greater than b[i]. It returns an iterator pointing to that position.
int reversed_num = 0;
while (num > reversed_num) {
reversed_num = reversed_num * 10 + num % 10;
num = num / 10;
}
return false;
}