Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
QUnabridged
//g++ 7.4.0 //Templated Queue Unabridged //code is created by Rezaul Hoque on Feb 27,2021 //please contact at jewelmrh@yahoo.com #include <iostream> using namespace std; template <class T> class Q{ public: Q(int s=100) : size(s+1) , first (0),last (0) { data = new T[size ];} ~Q(){ delete [] data;} void enqueue(const T& x){ data [last]=x; if(last == size) last = 1; else last = last +1; } T dequeue(){ T x; x= data[first ]; if(first == size) first = 1; else first = first +1; return x; } int isEmpty() const { return first ==last;} int isFull() const { return (last +1)==first;} private: int size, first, last; T* data; }; int main () { Q<char> q(20); Q<char> q1(10); Q<char> q3(2); Q<int> q2(2); Q<int> q4(4); for(int i=0; i<20; i++) { q.enqueue('~'); } q1.enqueue('\n'); q1.enqueue('Q'); q1.enqueue('U'); q1.enqueue('E'); q1.enqueue('U'); q1.enqueue('E'); q1.enqueue('\n'); q1.enqueue('F'); q1.enqueue('e'); q1.enqueue('b'); q3.enqueue(' '); q2.enqueue(2); q2.enqueue(7); q3.enqueue(' '); q4.enqueue(2); q4.enqueue(0); q4.enqueue(2); q4.enqueue(1); for(int i=0;i<20;i++){ cout<<q.dequeue(); } for(int i=0;i<10;i++){ cout<<q1.dequeue(); } cout<<q3.dequeue(); cout<<q2.dequeue()<<q2.dequeue(); cout<<q3.dequeue(); for(int i=0;i<4;i++){ cout<<q4.dequeue(); } for(int i=0;i<20;i++){ cout<<q.dequeue();} return 0; }
run
|
edit
|
history
|
help
0
Procesos E
kth smallest element in a matrix
Matrix spiral print
Namespace
fb_series
replace_copy_if-30-Seconds-of-C++
sample1
fibonacci
Stock buy/sell, maximum subarray problem
MINVEST