Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
queue-with-fixed-size
// Implement Queue with Limited Size of Arrays // https://www.cs.bu.edu/teaching/c/queue/array/types.html // 2 Implement Queue with Limited Size of Array // Implement a queue with a number of arrays, in which each array has fixed size. #include <vector> #include <iostream> using namespace std; class QueueFixed{ vector<vector<int>> v; int N; int read; int write; int total; public: QueueFixed(int n): N(n), read(0), write(0), total(0) { v = vector<vector<int>>(1,vector<int>(n,0)); } void push(int x) { //(*v.rbegin())[write++] = x; // write v[v.size()-1][write++] = x; total++; // counter++ if(write == N) { v.push_back(vector<int>(4,0)); // checking write = 0; } } int front(){ if(total ==0) return -1; return v[0][read]; } void pop() { if(total == 0) return; read++; total--; if(read == N) { v.erase(v.begin()); read = 0; } } int size(){ return total; } }; int main() { QueueFixed q(3); for(int i =0; i<11; i++) q.push(i); while(q.size()){ cout << q.front() << endl; q.pop(); } return 0; }
run
|
edit
|
history
|
help
0
Good pairs
BubDoubLinArray
C++ User Input #1
ddd
informatika / Cinta Avrille X MIPA 5
задача new
count pairs with given sum hashing
BintTree vertical sum
IndiSort
不带头结点的单链表