Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Queue Program
- // Date : 08.04.19
- #include<iostream>
- #include<cstdlib>
- #define max_size 20
- using namespace std;
- class queue_class{
- int queue_array[max_size];
- int front_index, rear_index;
- void insert_queue();
- void delete_queue();
- void display();
- public:
- queue_class(){ front_index = rear_index = 0; }
- void control_function();
- };
- void queue_class::control_function(){
- while(1){
- cout << "*****Welcome to Queue program*****\n"
- << "Press 1 to Insert.\n"
- << "Press 2 to Delete.\n"
- << "Press 3 to Display the Queue.\n"
- << "Press 4 to Exit.\n"
- << "Enter Your choice: ";
- int choice; cin >> choice;
- system("cls");
- if(choice == 1) insert_queue();
- else if(choice == 2) delete_queue();
- else if(choice == 3) display();
- else if(choice == 4) break;
- else cout << "Wrong Choice.\n\n";
- }
- return;
- }
- void queue_class::insert_queue(){
- if(rear_index == max_size){
- cout << "Queue Overflow\n";
- return;
- }
- else{
- cout << "Enter Element to insert: ";
- cin >> queue_array[rear_index++];
- }
- }
- void queue_class::delete_queue(){
- if(front_index == max_size || front_index == rear_index){
- cout << "Queue Underflow\n";
- return;
- }
- else{
- cout << "Element " << queue_array[front_index++]
- << " is deleted\n";
- }
- }
- void queue_class::display(){
- if(front_index == max_size || front_index == rear_index){
- cout << "Queue Underflow nothing to display!!!\n";
- return;
- }
- else{
- cout << "The elements in the Queue are: \n";
- for(int i = front_index; i < rear_index; i++){
- cout << queue_array[i] << ' ';
- }
- cout << endl;
- }
- }
- int main(){
- queue_class ob1;
- ob1.control_function();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement