Data Structure - Queue (Concept and C++ STL, Priority queue)
Queue
First In First Out(FIFO)
Linear Data Structure that can take out the data in order of FIFO
Take out data method is opposite to the stack
- Enqueue : load data into the queue
- Dequeue : substract data in the queue
queue - C++ STL Container
#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<int> q1;
q1.push(10); // call push_back
q1.push(20);
q1.push(30);
cout << q1.front() <<endl; //10
cout << q1.back() <<endl; //30
q1.pop();
cout << q1.front() <<endl; //20
}
#include <iostream>
#include <queue>
using namespace std;
int main()
{
queue<int> q;
q.push(1);
q.push(2);
q.push(3);
q.pop();
q.push(4);
q.pop();
while(!q.empty())
{
cout << q.front()<< " ";
q.pop();
}
//3 4
return 0;
}
Priority Queue
- When each data is inserted, the priority number of the data is put together
- The structure in which the order of extracting data differs according to the priority given when inserting data
큐의 활용
- Queue is used for multitasking in the operating system
- Like buffer, queue coordinates the interaction between two process scheduling running at different speeds