0% found this document useful (0 votes)
2 views

deqeu&prioQueue

The document provides an overview of the Standard Template Library (STL) in C++, focusing on the deque, queue, and priority queue containers. It details their characteristics, declaration methods, built-in functions, and complexities, emphasizing their dynamic sizing and operational functions. Additionally, it explains how to implement binary search using lower_bound and upper_bound functions on sorted arrays.

Uploaded by

mostafadelgouda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

deqeu&prioQueue

The document provides an overview of the Standard Template Library (STL) in C++, focusing on the deque, queue, and priority queue containers. It details their characteristics, declaration methods, built-in functions, and complexities, emphasizing their dynamic sizing and operational functions. Additionally, it explains how to implement binary search using lower_bound and upper_bound functions on sorted arrays.

Uploaded by

mostafadelgouda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

STL

(standard template library)


Deque
deque
• One of our sequensial container.
• Don’t have fixed size.
• It is very similar to list.
• We can use [] operator with deque.

- 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.

lower_bound(start,end,value) Returns an iterator to the first element that >= value


● If no such element returns end()
upper_bound(start,end,value) Returns an iterator to the first element that > value
● If no such element returns end()

Complexity is O(log n)
Notes
-We can find the index of lower and upper value
with the following:

lower_bound() – vec.begin() = index of lower bound value


upper_bound() – vec.begin() = index of upper bound value
Problem A :
queue
- One of our adaptor container.
- Don’t have fixed size.
- It is very similar to deque.
- We can’t use [] operator with queue.

- To declare a queue:
queue <data_type> name;
Ex:
queue<int> qu1;
queue<char> qu2;
queue<string> qu3;
Push(value) Push data into queue

Pop() Delete data from queue from front

Size() Return size of the queue

Empty() Return bool if the queue is empty or not

Clear() Delete all data from the queue

Back() Access the last elemnt

Front() Access the first element


example
Priority-queue
Priority-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.

To declare the priority queue


-priority_queue<dataType> name

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

Push(value) Push data into Priority-queue on the top

Pop() Delete data from Priority-queue from top

Size() Return size of the Priority-queue

Empty() Return bool if the Priority-queue is empty or not

Clear() Delete all data from the Priority-queue

top() Access the top elemnt of Priority-queue


Priority-queue
THANK YOU !!

You might also like