Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
CirclQ
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////// //Circular Queue(templated Queue) //this code is created by Rezaul Hoque on August 29,2022;update: 18:08 //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; ///////////////////////////////////////////////////////////////////////////// #include <iostream> using namespace std; template <class T> class Q{ public: Q(int s=100) : size(s+1) , first (-1),last (-1) { data = new T[size ];} ~Q(){ delete [] data;} int isEmpty() const { if(first==-1) return 1; else return 0; } int isFull() const { if(first==0 && last == size-1) {return 1;} if(first==last+1) {return 1;} return 0; } void enqueue(const T& x){ if(isFull()){ std::cout<<"Queue is full\n";} else { if(first==-1) first=0; last=(last+1)%size; data [last]=x; } } T dequeue(){ T x; if(isEmpty()){ std::cout<<"Queue is empty. \n"; return -1; } else { x= data[first ]; if(first == last) { first = -1; last=-1; } else { first =( first +1)%size;} return x; } } int size, first, last; T* data; }; int main () { Q<char> q1(21); q1.enqueue('Q'); q1.enqueue('U'); q1.enqueue('E'); q1.enqueue('U'); q1.enqueue('E'); q1.enqueue('\n'); q1.enqueue('A'); q1.enqueue('u'); q1.enqueue('g'); q1.enqueue(' '); q1.enqueue('2'); q1.enqueue('9'); q1.enqueue(','); q1.enqueue('2'); q1.enqueue('0'); q1.enqueue('2'); q1.enqueue('2'); for(int i=q1.first;i<=q1.last;i++){ cout<<q1.data[i]; } return 0; }
run
|
edit
|
history
|
help
0
kth smallest element in a matrix
Scemo
References Pt 1 C++
BinSearch
hh
Hello
Microsoft - MaxEmployeeAttendence (R repititions - DP solution bitmask)
Question 1
AVL - ith element
Karibu