PRESENTATI
ON
• Deques
• Priority
queue
Here is where your presentation begins
DEQUES
• Double-ended queues are sequence containers with
the feature of expansion and contraction on both
ends
• Double-ended queues are a special case of queues
where insertion and deletion operations are possible
at both the ends.
• TYPES: can be implemented as a circular or linear
structure
DEQUES
COMMAN METHODS IN DEQUES
• PUSH_BACK()
• PUSH_FRONT()
• POP_FRONT()
• POP_BACK()
• FRONT()
• BACK()
• isEmpty()
• size()
#include <deque> Implementatio
#include <iostream>
using namespace std;
void showdq(deque<int> g)
n OUTPUT
{
deque<int>: :iterator it;
for (it = g.begin(); it != g.end(); ++it) The deque gquiz is : 15 20 10
cout << '\t' << *it; 30
cout << '\n';
}
int main() gquiz.size() : 4
{
deque<int> gquiz;
gquiz.max_size() :
gquiz.push_back(10); 4611686018427387903
gquiz.push_front(20);
gquiz.at(2) : 10
gquiz.push_back(30);
gquiz.push_front(15); gquiz.front() : 15
cout << "The deque gquiz is : "; gquiz.back() : 30
showdq(gquiz);
gquiz.pop_front() : 20 10 30
cout << "\ngquiz.size() : " << gquiz.size();
cout << "\ngquiz.max_size() : " <<
gquiz.max_size();
gquiz.pop_back() : 20 10
cout << "\ngquiz.at(2) : " << gquiz.at(2);
cout << "\ngquiz.front() : " << gquiz.front();
cout << "\ngquiz.back() : " << gquiz.back();
cout << "\ngquiz.pop_front() : ";
gquiz.pop_front();
showdq(gquiz);
cout << "\ngquiz.pop_back() : ";
gquiz.pop_back();
showdq(gquiz);
DEQUES
DIFFERENCE BETWEEN QUEUE AND
queu Dequ
DEQUEe
1 Element can only be inserted
1.Elements can be inserted from
e
at the end of the data structure both ends of the data structure.
2. Elements can only be removed 2Elements can be removed from
from the front of the data both ends of the data structure.
structure. .
3.Deque can be used to implement
3.Queues are a specialized data
the functionalities of both Stack
structure that uses the FIFO
(LIFO approach i.e., Last In First
approach i.e., First In First Out
Out) and Queue (FIFO approach
i.e., First In First Out).
4.Deque can be traversed using
4.Queue elements cannot be
iterator
accessed with the help of an
iterator.
PRIORITY
QUEUE
• A priority queue is an abstract data type that operates
similar to a regular queue or stack, but with an added
feature: each element has a priority associated with it.
• In a priority queue, elements are served based on their
priority rather than their order in the queue
--Implementation--
• Arrays
• Linked list
• Heap data structure
• Binary search tree
--Types--
• Max-Priority Queue:
• Min-Priority Queue
Implementation -Max-Priority
#include <iostream>
#include <queue>
Queue: output
using namespace std; Array: 10 2 4 8 6 9
// driver code Priority Queue: 10 9 8 6 4 2
int main()
{
int arr[6] = { 10, 2, 4, 8, 6, 9 };
// defining priority queue
priority_queue<int> pq;
// printing array
cout << "Array: ";
for (auto i : arr) {
cout << i << ' ';
}
cout << endl;
// pushing array sequentially one by one
for (int i = 0; i < 6; i++) {
pq.push(arr[i]);
}
// printing priority queue
cout << "Priority Queue: ";
while (!pq.empty()) {
cout << pq.top() << ' ';
pq.pop();
}
return 0;
}
#include <iostream> Implementation - min Priority
#include <queue> output
using namespace std; Queue: Array: 10 2 4 8 6 9
void showpq( Priority Queue : 2 4 6 8 9 10
priority_queue<int, vector<int>, greater<int> > g)
{
while (!g.empty()) {
cout << ' ' << g.top();
g.pop();
}
cout << '\n';
}
void showArray(int* arr, int n)
{
for (int i = 0; i < n; i++) {
cout << arr[i] << ' ';
}
cout << endl;
}
// Driver Code
int main()
{
int arr[6] = { 10, 2, 4, 8, 6, 9 };
priority_queue<int, vector<int>, greater<int> > gquiz(
arr, arr + 6);
cout << "Array: ";
showArray(arr, 6);
cout << "Priority Queue : ";
showpq(gquiz);
return 0;
}
PRIORITY
QUEUE
THANK
YOU