Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int head = -1 , tail = -1 , array[3] , size = 3; //declare head and tail as -1 and took a array with size 3
- //ISFULL
- bool isEmpty(){
- if(head == -1 && tail == -1){
- return true;
- } //check the condition is it empty??
- return false;
- }
- //ISEMPTY
- /*bool isFull(){
- if(tail > size - 1){
- return true;
- }//check the condition is it full??
- return false;
- }*/
- bool isFull(){
- if(tail >= size - 1){
- return true;
- }//check the condition is it full??
- return false;
- }
- //ENQUEUE
- void enqueue(int val){
- head = 0;
- if(isFull() == false){
- tail++;
- array[tail] = val; //store the parameter value into the tail index
- }else{
- cout << "Array is full" << endl;
- }//check the condition and add a value into the tail section
- }
- //DEQUEUE
- void dequere(){
- if(isEmpty()){
- return;
- }else{
- if(tail == 0 && head == 0){
- head++;//when we use only one data.
- }else{
- array[head];
- head++;
- }
- }//check the condition and remove the head data or first data from the queue
- }
- //PEEK
- int peek(){
- if(!(isEmpty())){
- return array[head];//return the peek data from the head section.
- }
- return -1;//return -1 if the array is full.
- }
- //Main function
- int main(){
- peek();
- enqueue(100);
- enqueue(200);
- enqueue(300);
- enqueue(300);
- //dequere();
- cout << peek();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement