Created
August 26, 2019 16:48
-
-
Save jkotra/5f0dfff34406c4285c15a73c87a6535a to your computer and use it in GitHub Desktop.
Queue in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Queue in c++ | |
| *(FOR RECORD WORK) | |
| *Jagadeesh Kotra (github.com/jkotra) | |
| *Dt: 26.08.2019 */ | |
| #include <iostream> | |
| using namespace std; | |
| class Queue{ | |
| private: | |
| int q[5]{}; | |
| const int maxsize = 5; | |
| int front,rear; | |
| public: | |
| Queue(); | |
| void insert(int x); | |
| int delet(); | |
| bool isempty(); | |
| bool isfull(); | |
| }; | |
| Queue::Queue() { | |
| front = -1; | |
| rear = -1; | |
| } | |
| void Queue::insert(int x) { | |
| if (isfull()) | |
| cout << "Queue is full." << endl; | |
| else { | |
| rear++; | |
| q[rear] = x; | |
| } | |
| } | |
| int Queue::delet() { | |
| if (isempty()) | |
| cout << "Queue is empty." << endl; | |
| else { | |
| front++; | |
| return q[front]; | |
| } | |
| } | |
| bool Queue::isempty() { | |
| return front == rear; | |
| } | |
| bool Queue::isfull() { | |
| return rear == (maxsize-1); | |
| } | |
| int main() { | |
| Queue q; | |
| q.insert(10); | |
| q.insert(20); | |
| cout << q.delet() << " deleted from queue" << endl; | |
| cout << q.delet() << " deleted from queue" << endl; | |
| return 0; | |
| } | |
| /* Output : | |
| * 10 deleted from queue | |
| * 20 deleted from queue | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment