Skip to content

Instantly share code, notes, and snippets.

@ahmedalkabir
Last active November 10, 2018 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedalkabir/18f645789fc355bf5fdf5b2e0a92245e to your computer and use it in GitHub Desktop.
Save ahmedalkabir/18f645789fc355bf5fdf5b2e0a92245e to your computer and use it in GitHub Desktop.
QUEUE Imlementation
#include<iostream>
using namespace std;
int QUEUE[100], s_of_element, front, back;
void enqueue(void){
int temp;
if(back == s_of_element){
cout << "QUEUE IS FULL" << endl;
}else{
cout << "\nEnter a value to be pushed: ";
cin >> temp;
QUEUE[back++] = temp;
}
}
int dequeue(void) {
if(front == back){
cout << "QUEUE IS EMPTY" << endl;
}else{
return QUEUE[front++];
}
}
void show(void){
if(front != back){
cout << "The elements of QUEUE is ...... " << endl;
for(int i=front; i < back; i++)
cout << "The Element : " << QUEUE[i] << endl;
cout << "\n\nPress Next Choice " << endl;
}else{
cout << "The QUEUE is empty " << endl;
}
}
int main(void){
int choice;
front = 0, back = 0;
cout << " Simple QUEUE Implementation using Array 0" << endl;
cout << "Enter the size of QUEUE MAX=100: ";
cin >> s_of_element;
cout << " 1.INSERT(ENQUEUE)\n 2.DELETE(DEQUEUE)\n 3.SHOW\n 4.EXIT" << endl;
do{
cout << "Enter YOUR Choice :";
cin >> choice;
switch(choice){
case 1:
enqueue();
break;
case 2:
cout << "The dequeued element is " << dequeue() << endl;
break;
case 3:
show();
break;
case 4:
cout << "\n EXITING....." << endl;
break;
default:
cout << "\n\t Invaild option " << endl;
break;
}
}while(choice != 4);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment