Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Q
//g++ 7.4.0 #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 insert(const T& x){ data [last ++% size ]=x;} T remove (){ return data[first ++%size];} int isEmpty() const { return first ==last;} int isFull() const { return (last +1)%size==first;} private: int size, first, last; T* data; }; int main () { Q<char> q(4); q.insert('H'); q.insert('I'); q.insert('T'); q.insert('H'); if(q.isFull()) cout<< "Queue is full.\n"; else cout<<"Queue is not full.\n"; cout<<q.remove()<<endl; cout<<q.remove()<<endl; q.insert(' '); q.insert('l'); if(q.isFull()) cout<< "Queue is full.\n"; else cout<<"Queue is not full."; cout<<q.remove()<<endl; cout<<q.remove()<<endl; cout<<q.remove()<<endl; cout<<q.remove()<<endl; if(q.isEmpty()) cout<< "Queue is empty."; else cout<<"Queue is not empty."; return 0; }
run
|
edit
|
history
|
help
0
TraiectorieIdeala
ListCPP
.
czekolada
Org
Dar
Some-stuff
Kth smallest element
isBST
C++ User Input #1