deqeu&prioQueue
deqeu&prioQueue
- To declare a deque:
deque <data_type> name;
Ex:
deque<int> dqu1;
deque<char> dqu2;
deque<string> dqu3;
Our built-in-functions
• Dq.push_back(value)
• Dq.push_front(value)
• Dq.pop_back()
• Dq.pop_front()
• Dq.size()
• Dq.empty()
• Dq.front()
• Dq.back()
Complexity is O(1)
example
Algorisms again
we can use the following function with only sorted array to implement
the concept of binary search.
Complexity is O(log n)
Notes
-We can find the index of lower and upper value
with the following:
- To declare a queue:
queue <data_type> name;
Ex:
queue<int> qu1;
queue<char> qu2;
queue<string> qu3;
Push(value) Push data into queue
Priority queue is adaptor container that take the values and sort it in decreasing
order so the the most great value will be in the top.
EX:-
priority_queue<int> pq;
priority_queue<char> pq;
priority_queue<string> pq;
Priority-queue
Note :
If you want to sort the elements in increasing order use this declaration :
-priority_queue<dataType,vector<dataType>,greater<dataType>> pq;
EX:-
priority_queue<int,vector<int>,greater<int>> pq;
priority_queue<char,vector<char>,greater<char>> pq;
priority_queue<string,vector<string>,greater<string> pq;
Priority-queue