-->





Translate

Showing posts with label queue. Show all posts
Showing posts with label queue. Show all posts

Queue c++ project source code using array, linked list and doubly/circular linked list

2 comments
Download C++ project source code for queue implementation using an array, linked list and circular linked list.

Each data structure has its own functions. Users can select from the menu for data type selection to build a queue.

All data structures have basic queue functions. En-queue, De-queue, show front, show queue, etc.

Project source code. It has been tested on Code Blocks C++ IDE.

#include<iostream>
#include<windows.h>

using namespace std;
// Queue for array
void enqueue(int);
void dequeue();
int isempty();
int isfull();
void array_call();
void show();
const int total = 2;
int marks[total];
int rear = -1; //rear mean last element of queue
int front = 0;//front mean first element of queue
int counter = 0;

// Queue for Linklist
struct list
{
 int data;
 list * next;
};
list *f, *c, *p, *temp;
int linklist_counter = 0;
void linklist_insert();
void linklist_call();
void linklist_dequeu();
void linklist_show();
void linklist_front();
int linklist_isempty();

//Queue for Double Linklist
struct dlist {
 dlist * prev;
 int data;
 dlist * next;
};
dlist *first, *current, *previos, *tamp;
int dlinklist_counter = 0;
void dlinklist_insert();
void dlinklist_call();
void dlinklist_dequeu();
void dlinklist_show();
void dlinklist_front();

int main()
{
zee:
 system("cls");
 int i;
 cout << "\t\t\t\t Welcome in Queue  \n 1- Array \n 2- Link List \n 3- Double Link List \n 4- EXIT \n";
 cin >> i;

 switch (i)
 {
 case 1:
  array_call();
  goto zee;
 case 2:
  linklist_call();
  goto zee;
 case 3:

  dlinklist_call();
  goto zee;
 case 4:
  break;
 default:
  cout << " You enter invalid number PLZ Select again \n";
  system("pause");
  goto zee;
 }
 return 0;
}

// function of Array
void array_call()
{
start:
 system("cls");
 cout << "\t\t\t\t Welcome in Queue with Array";
 int input;
 cout << "\n 1- Enqueu \n 2- Dequeu \n 3- Front\n 4- Show all data \n 5- Exit from Queue in Array \n";
 cin >> input;
 switch (input)
 {
 case 1:
 {int z; z = isfull();
 if (z)
 {
  int y;//y is input whiich you insert in queue
  cout << "Enter you number";
  cin >> y;
  enqueue(y);
  cout << " Number entered \n";
  system("pause");
 }
 else
 {
  cout << "Your Queue is full \n";
  system("pause");
 }
 goto start;
 break;
 }

 case 2:
 { int a; a = isempty();
 if (a)
 {
  dequeue();
  cout << "Number deleted \n ";
  system("pause");
 }
 else
 {
  cout << "Your Queue is Empty \n";
  system("pause");
 }
 goto start;
 break;
 }

 case 3:
 {
  int a; a = isempty();
  if (a)
   cout << "\n Your front value is " << marks[front]<<endl;
  else
   cout << "Your Queue is Empty"<<endl;
  system("pause");
  goto start;
  break;
 }

 case 4:
 {
  int a; a = isempty();
  if (a)
   show();
  else
   cout << "Your Queue is Empty"<<endl;
  system(" pause");
  goto start;
 }

 case 5:
 {
  break;
 }
 default:
  cout << "\n You enter invalid Number \n";
  system("pause");
  goto start;
  break;
 }

}
void enqueue(int x)
{
 rear = (rear + 1) % total;
 marks[rear] = x;
 counter = counter + 1;
}
void dequeue()
{
 front = (front + 1) % total;
 counter = counter - 1;
}
int isempty()
{
 return(counter != 0);
}
int isfull()
{
 return(counter != total);
}
void show()
{
 int j = front;
 for (int i = 0; i < counter; i++)
 {

  cout << " " << marks[j];
  j++;
  j = j%total;
 }
}

//function of LINK LIST
void linklist_call()
{
linklist_start:
 system("cls");
 cout << "\t\t\t\t Welcome in linklist Queue";
 int input;
 cout << "\n 1- Enqueu \n 2- Dequeu \n 3- show list \n 4- Front\n 5- Exit\n";
 cin >> input;
 switch (input)
 {
 case 1:
  linklist_insert();
  cout << " Number entered \n";
  system("pause");
  goto linklist_start;
 case 2:
  linklist_dequeu();
  goto linklist_start;
 case 3:
  linklist_show();
  goto linklist_start;
 case 4:
  linklist_front();
  goto linklist_start;
 case 5:
  break;
 default:
  cout << " You enter invalid number ";
  system("pause");
  goto linklist_start;
 }
}
void linklist_insert()
{
 c = new list;
 if (linklist_counter == 0)
 {
  f = c;
  p = c;
  cout << " Enter data ";
  cin >> c->data;
 }
 else
 {
  p->next = c;
  p = c;
  cout << " Enter data";
  cin >> c->data;
 }
 c->next = NULL;
 linklist_counter++;
}
void linklist_dequeu()
{
 if (linklist_counter == 0)
 {
  cout << " Queue is empty";
  system("pause");
 }
 else
 {
  f = f->next;
  linklist_counter--;
  cout << "Number deleted \n ";
  system("pause");
 }
}
void linklist_show()
{
 int emp = linklist_isempty();
 if (emp)
 {
  temp = f;
  while (temp->next != NULL)
  {
   cout << " " << temp->data;
   temp = temp->next;
  }
  cout << " " << temp->data;
 }
 else
 {
  cout << " Queue is empty";
 }
 system("pause");
}
void linklist_front()
{
 int emp = linklist_isempty();
 if (emp)
 {
  cout << " " << f->data;
 }
 else
 {
  cout << " Queue is empty";
 }
 system("pause");
}
int linklist_isempty()
{
 return(linklist_counter != 0);
}

//function of DOUBLE LINK LIST
void dlinklist_call()
{
dlinklist_start:
 system("cls");
 cout << "\t\t\t\t Welcome in Double linklist Queue";
 int dinput;
 cout << "\n 1- Enqueu \n 2- Dequeu \n 3- show list \n 4- Front\n 5- Exit\n";
 cin >> dinput;
 switch (dinput)
 {
 case 1:
  dlinklist_insert();
  cout << " Number entered \n";
  system("pause");
  goto dlinklist_start;
 case 2:
  dlinklist_dequeu();
  cout << "Number deleted \n ";
  system("pause");
  goto dlinklist_start;
 case 3:
  dlinklist_show();
  goto dlinklist_start;
 case 4:
  dlinklist_front();
  goto dlinklist_start;
 case 5:
  break;
 default:
  cout << " You enter invalid number ";
  system("pause");
  goto dlinklist_start;
 }
}
void dlinklist_insert()
{
 current = new dlist;
 if (dlinklist_counter == 0)
 {
  previos = current;
  first = current;
  current->prev = NULL;
  cout << " Enter Data ";
  cin >> current->data;
 }
 else
 {
  previos->next = current;
  current->prev = previos;
  previos = current;
  cout << " Enter Data ";
  cin >> current->data;
 }
 current->next = NULL;
 dlinklist_counter++;
}
void dlinklist_dequeu()
{
 if (dlinklist_counter == 0)
 {
  cout << " Queue is empty";
  system("pause");
 }
 else
 {
  first = first->next;
  dlinklist_counter--;
 }
}
void dlinklist_show()
{
 if (dlinklist_counter == 0)
 {
  cout << " Queue is empty";
 }
 else
 {
  tamp = first;
  while (tamp->next != NULL)
  {
   cout << " " << tamp->data;
   tamp = tamp->next;
  }
  cout << " " << tamp->data;
 }
 system("pause");
}
void dlinklist_front()
{
 if (dlinklist_counter == 0)
 {
  cout << " Queue is empty";
 }
 else
 {
  cout << " " << first->data;
 }
 system("pause");
}



Project output images.

download c++ queue project source code
queue using array function

c++ queue using doubly or circular linked list


c++ queue using link list


Also, find more c++ simple projects


Read More...

doubly linked list queue in c++ source code

Leave a Comment
Doubly or circular linked list in c++ programming example using the queue data structure
This c++ source code of the queue has four main functions.
  1. enqueue
  2. dequeue
  3. show front
  4. show list
It uses the concept of functions, pointer, struct and switch, etc..

#include<iostream>
#include<windows.h>

using namespace std;

//Queue for Double Linklist
struct dlist {
	dlist * prev;
	int data;
	dlist * next;
};
dlist *first, *current, *previos, *tamp;
int dlinklist_counter = 0;
void dlinklist_insert();
void dlinklist_call();
void dlinklist_dequeu();
void dlinklist_show();
void dlinklist_front();

int main()
{
	system("cls");

    dlinklist_call();
   return 0;
}


//function of DOUBLE LINK LIST
void dlinklist_call()
{
dlinklist_start:
	system("cls");
	cout << "\t\t\t\t Welcome in Double linklist Queue";
	int dinput;
	cout << "\n 1- Enqueu \n 2- Dequeu \n 3- show list \n 4- Front\n 5- Exit\n";
	cin >> dinput;
	switch (dinput)
	{
	case 1:
		dlinklist_insert();
		cout << " Number entered \n";
		system("pause");
		goto dlinklist_start;
	case 2:
		dlinklist_dequeu();
		cout << "Number deleted \n ";
		system("pause");
		goto dlinklist_start;
	case 3:
		dlinklist_show();
		goto dlinklist_start;
	case 4:
		dlinklist_front();
		goto dlinklist_start;
	case 5:
		break;
	default:
		cout << " You enter invalid number ";
		system("pause");
		goto dlinklist_start;
	}
}
void dlinklist_insert()
{
	current = new dlist;
	if (dlinklist_counter == 0)
	{
		previos = current;
		first = current;
		current->prev = NULL;
		cout << " Enter Data ";
		cin >> current->data;
	}
	else
	{
		previos->next = current;
		current->prev = previos;
		previos = current;
		cout << " Enter Data ";
		cin >> current->data;
	}
	current->next = NULL;
	dlinklist_counter++;
}
void dlinklist_dequeu()
{
	if (dlinklist_counter == 0)
	{
		cout << " Queue is empty";
		system("pause");
	}
	else
	{
		first = first->next;
		dlinklist_counter--;
	}
}
void dlinklist_show()
{
	if (dlinklist_counter == 0)
	{
		cout << " Queue is empty";
	}
	else
	{
		tamp = first;
		while (tamp->next != NULL)
		{
			cout << " " << tamp->data;
			tamp = tamp->next;
		}
		cout << " " << tamp->data;
	}
	system("pause");
}
void dlinklist_front()
{
	if (dlinklist_counter == 0)
	{
		cout << " Queue is empty";
	}
	else
	{
		cout << " " << first->data;
	}
	system("pause");
}



Program output:
doubly linked list queue in c++
Read More...

queue data structure implementation c++ code using linked list

Leave a Comment
C++ program to implement queue data structure using linked list

It uses struct, pointers, switch and functions concept. Every queue operation has its own function. User selects its desired operation from the menu.
It has the following functions

  1. Enqueue
  2. Dequeue
  3. Show front 
  4. Show All


    #include<windows.h>
    #include<iostream>
    using namespace std;

    // Queue for Linklist
    struct list
    {
     int data;
     list * next;
    };
    list *f, *c, *p, *temp;
    int linklist_counter = 0;
    void linklist_insert();
    void linklist_call();
    void linklist_dequeu();
    void linklist_show();
    void linklist_front();
    int linklist_isempty();

    int main()
    {
     linklist_call();
     return 0;
    }
    //function of LINK LIST
    void linklist_call()
    {
    linklist_start:
     system("cls");
     cout << "\t\t\t\t Welcome in linklist Queue";
     int input;
     cout << "\n 1- Enqueue \n 2- Dequeue \n 3- show list \n 4- Front\n 5- Exit\n";
     cin >> input;
     switch (input)
     {
     case 1:
      linklist_insert();
      cout << " Number entered \n";
      system("pause");
      goto linklist_start;
     case 2:
      linklist_dequeu();
      goto linklist_start;
     case 3:
      linklist_show();
      goto linklist_start;
     case 4:
      linklist_front();
      goto linklist_start;
     case 5:
      break;
     default:
      cout << " You enter invalid number ";
      system("pause");
      goto linklist_start;
     }
    }
    void linklist_insert()
    {
     c = new list;
     if (linklist_counter == 0)
     {
      f = c;
      p = c;
      cout << " Enter data ";
      cin >> c->data;
     }
     else
     {
      p->next = c;
      p = c;
      cout << " Enter data";
      cin >> c->data;
     }
     c->next = NULL;
     linklist_counter++;
    }
    void linklist_dequeu()
    {
     if (linklist_counter == 0)
     {
      cout << " Queue is empty";
      system("pause");
     }
     else
     {
      f = f->next;
      linklist_counter--;
      cout << "Number deleted \n ";
      system("pause");
     }
    }
    void linklist_show()
    {
     int emp = linklist_isempty();
     if (emp)
     {
      temp = f;
      while (temp->next != NULL)
      {
       cout << " " << temp->data;
       temp = temp->next;
      }
      cout << " " << temp->data;
     }
     else
     {
      cout << " Queue is empty";
     }
     system("pause");
    }
    void linklist_front()
    {
     int emp = linklist_isempty();
     if (emp)
     {
      cout << " " << f->data;
     }
     else
     {
      cout << " Queue is empty";
     }
     system("pause");
    }
    int linklist_isempty()
    {
     return(linklist_counter != 0);
    }


Read Also: Array based queue c++ code example
program output:



c++ program for implementing queue using linked list.
linked list queue c++


As a beginner, this code helps the student to clear the concept of the queue using a linked list. It can be used as started code for beginners. find a full  c++ array based queue project.

also read other projects here: c++ simple projects
Read More...

queue implementation in c++ programming using array

Leave a Comment
Simple c++ queue using array implementation example

which uses function loops and conditional statement concepts. 
Queue size is fixed in a variable name 'total which is equal to 5 it can be changed as a requirement.
User select function from menu and enter input.
We have the following functions in queue

  1. Enqueue 
  2. Dequeue
  3. Is Empty (check if the queue is empty)
  4. Is Full  
  5. Show All
Prototypes are
void enqueue(int);
void dequeue();
int isempty();
int isfull();
void show();


C++ Queue Source Code


#include<iostream>
#include<windows.h>

using namespace std;
// Queue for array
void enqueue(int);
void dequeue();
int isempty();
int isfull();
void array_call();
void show();
const int total = 5;
int marks[total];
int rear = -1; //rear mean last element of queue
int front = 0;//front mean first element of queue
int counter = 0;

int main()
{
    array_call();
    return 0;
}

// function of Array
void array_call()
{
start:
 system("cls");
 cout << "\t\t\t\t Welcome in Queue with Array";
 int input;
 cout << "\n 1- Enqueu \n 2- Dequeu \n 3- Front\n 4- Show all data \n 5- Exit from Queue in Array \n";
 cin >> input;
 switch (input)
 {
 case 1:
 {int z; z = isfull();
 if (z)
 {
  int y;//y is input whiich you insert in queue
  cout << "Enter you number: ";
  cin >> y;
  enqueue(y);
  cout << " Number entered \n";
  system("pause");
 }
 else
 {
  cout << "Your Queue is full \n";
  system("pause");
 }
 goto start;
 break;
 }

 case 2:
 { int a; a = isempty();
 if (a)
 {
  dequeue();
  cout << "Number deleted \n ";
  system("pause");
 }
 else
 {
  cout << "Your Queue is Empty \n";
  system("pause");
 }
 goto start;
 break;
 }

 case 3:
 {
  int a; a = isempty();
  if (a)
   cout << "\n Your front value is " << marks[front]<<endl;
  else
   cout << "Your Queue is Empty"<<endl;
  system("pause");
  goto start;
  break;
 }

 case 4:
 {
  int a; a = isempty();
  if (a)
   show();
  else
   cout << "Your Queue is Empty"<<endl;
  system(" pause");
  goto start;
 }

 case 5:
 {
  break;
 }
 default:
  cout << "\n You enter invalid Number \n";
  system("pause");
  goto start;
  break;
 }

}
void enqueue(int x)
{
 rear = (rear + 1) % total;
 marks[rear] = x;
 counter = counter + 1;
}
void dequeue()
{
 front = (front + 1) % total;
 counter = counter - 1;
}
int isempty()
{
 return(counter != 0);
}
int isfull()
{
 return(counter != total);
}
void show()
{
 int j = front;
 for (int i = 0; i < counter; i++)
 {
  cout << " " << marks[j];
  j++;
  j = j%total;
 }
}


Run the program



Example input output
queue implementation in c++ using array
Input-output

See also: C++ Project Using Array Based Queue

This example may help beginner students to understand the concept of an array using a queue. It is recommended to change the code add validations etc.


Read More...

Array based Queue c++ simple project

Leave a Comment
In this c++ tutorial we will discuss  about Array Based Queue C++ project which have 10 functions including main function. User will select an option from main menu function and the respective function will be called. The code is for array based queue implementation. It comprises of various operations that can be performed on array based queue. This code can be used as a project or self-assignment by beginners of data structure. It is recommended to understand the code thoroughly mainly the “logic” then try to create logic for each individual function by yourself. It will surely enhance your coding capability

What is a Queue?
  • List of items arranged on basis of first in and first out principal is called queue.
  • It has 2 ends.
  • Data can be considered as to pass through hollow cylinder.
  • Data enters from one end and leaves from another end.
  • Data only moves in one direction.


Characteristics Of Queue:


  • It works on the FIFO (first in first out) principal.
  • It is ordered list and has elements/data of same type.
  • It doesn’t allow duplication of data.
  •  Enqueue function is used to insert new item in queue.
  • Dequeue function is used to remove any item from queue.
  •  If you want to dequeue any random item from queue, you will have to first dequeuer all items above it. Then remove the item you want. Then enqueue dequeued items accordingly.
cpp queue source code
queue image example 


Real World Examples:


  1. People standing in a queue for submission of their bills in bank. The person who came first will submit bill first. The person who came later will submit bill later.
  2. Cars on one way road. The car that entered first will exists first while the car that entered later will exit later.


Array Based Queue in C++ Data Structures
It is a linear data structure in which insertion of data/element takes places from end (rear) and deletion of data/element takes place from front (head).It allows you to store a data in form of array.

Project Overview:

Below I am going to share with you a c++ source code that is compiled using dev c++ compiler. The code is for array based queue implementation. It comprises of various operations that can be performed on array based queue. This code can be used as a project or self-assignment by beginners of data structure. It is recommended to understand the code thoroughly mainly the “logic” then try to create logic for each individual function by yourself. It will surely enhance your coding capability.

Code:

#include<iostream>     //header files
#include<conio.h> //header files
#include<stdlib.h>      //header files
#include<stdio.h>     //header files
using namespace std;

//////////////////////////////////////////////////////////////////////////////////////
/*declaration of global variables*/
/* front will show first index of array, initiated with -1 that shows that nothing is present at first position in queue*/
int front=-1;   
/* rear will show first last index of array, initiated with -1 that shows that nothing is present at last position in queue*/
int rear=-1;
int index=0;          // index will represent that how long is queue
int *queue=new int[index];      // for dynamical creation of queue
//////////////////////////////////////////////////////////////////////////////////////
/*declaration of functions*/
The functions below are named in such a way that they will clearly reveal what they are meant for
//////////////////////////////////////////////////////////////////////////////////////
void createqueue();
void enqueue(int a);
int dequeue();
void deletequeue();
void clearqueue();
int isfull();
int isempty();
void find();
void display();
void menu();

/////////////////////////////////////////////////////////////////////////////////////
The function below is the first function that would be called when code is executed. It will display a menu having different functionalities. Just select the number corresponding to operation you want to perform and then you will be on your way to go 
////////////////////////////////////////////////////////////////////////////////////
void menu()
{ 
     system("pause");     /*built in function supported by dev c++ to pause a screen until “enter” or any key is entered to proceed further.*/
     system("cls");   /*It will remove any garbage value that may appear on screen*/
     int option;
     cout<<"****welcome to queue application****\n";
     cout<<"press 1 to create queue\n";
     cout<<"press 2 to display queue\n";
     cout<<"press 3 to delete queue\n";
     cout<<"press 4 to clear queue\n";
     cout<<"press 5 to find number in queue\n";
     cout<<"press 6 to enqueue\n";
     cout<<"press 7 to dequeue\n";
     cout<<"press 8 to check if queue is full\n";
     cout<<"press 9 to check if queue is empty\n";
     cout<<"press 0 to exit\n";
     cout<<"enter option\n";
     cin>>option;
//////////////////////////////////////////////////////////////////////////////////////
Below I have used a switch to call various functions. If you are a beginner and don’t have any idea about “switch” you can go ahead with if-else statements but their drawback is they mess up everything, make confusions as code gets lengthy. 
/////////////////////////////////////////////////////////////////////////////////////     
     switch(option)
     {
     case 1:   // this case will simply call create queue function and will create it.
          createqueue();
          menu();
          break;
          
     case 2:   // this case will call display function and will display queue items
          display();
          menu();
          break;
     
     case 3:  // this function will delete whole queue by calling delete queue function
          deletequeue();
          menu();
          break;
     
     case 4:     // it will only clear items in queue but empty queue will still exist
          clearqueue();
          menu();
          break;
     
     case 5:   // it will search for required item in queue
          find();
          menu();
          break;
     
     case 6:    //
          {
          int a;
/*the check below will be used throughout the code to check if queue is created or not. Note the point that whenever front and rear will have negative value it means that array does not exist because array’s index can never be negative*/
          if(front==-1&&rear==-1)
          cout<<"queue not created\n";
          else  
          if(isfull()==1)
          
          cout<<"queue is already full\n";
                     
          else
          {
          cout<<"enter element to enqueue\n";
          cin>>a;
          enqueue(a);
          }
          menu();
          }
          break;
     
     case 7:
          {
          if(front==-1&&rear==-1)
          cout<<"queue not created\n";
          else 
          if(isempty()==1)
          {
          cout<<"queue is already empty\n";
          }
          else
          {
          cout<<"element dequeued is :"<<dequeue();
          cout<<endl;                
          }
          menu();
          } 
          break;
     
     case 8:
          {     
          int a;     
          if(front==-1&&rear==-1)
          cout<<"queue not created\n";
          else   
          isfull();
          if(a==1)
          cout<<"queue is full\n";
          else
          cout<<"queue is not full\n";
          }
          menu();
          break;
     
     case 9:
          {
          int a;     
          if(front==-1&&rear==-1)
          cout<<"queue not created\n";
          else   
          isempty();
          if(a==1)
          cout<<"queue is empty\n";
          else
          {
          cout<<"queue is not empty\n";   
          }
          menu();
          }
          break;
          
     case 0:
          exit(0);
          break;
   
    default:
          cout<<"invalid input\n";
          break;
          }
          }
//////////////////////////////////////////////////////////////
          
void createqueue()
{
/*The loop below will continue till you enter correct size of queue that must be greater than zero*/
     do
     {
     cout<<"enter size of queue:";
     cin>>index;
     }
     while(index<=0);
//////////////////////////////////////////////////////////////////////////////////////
Suppose you entered 10 then, queue will be like that
Front/rear
queue input value
enter queue value = 10
Dequeue/ Enqueue ////////////////////////////////////////////////////////////////////////////////////// /*The loop below will continue till you enter accurate current size that must be positive and less then index value. The “rear” here is pointing last index. */ do { cout<<"enter current size of queue:"; cin>>rear; } while(rear>index||rear<0); ///////////////////////////////////////////////////////////////////////////////// Suppose you entered rear=5 so,
c++ enter input
queue input = 5
////////////////////////////////////////////////////////////////////////////////// front=0; // front always start from zero it could be 1 also. cout<<"enter elements\n"; for(int i=front;i<rear;i++)// loop will start from ‘0’ and continue till “rear” value { cin>>queue[i]; } cout<<"queue is successfully created\n"; }
c++ queue created function
queue created c++
////////////////////////////////////////////////////////////////////////////////////// The function below will be used for display. ////////////////////////////////////////////////////////////////////////////////////// void display() { if(front==-1&&rear==-1) cout<<"queue not created\n"; else if(front<rear) { cout<<"total number of elements in queue are:"; cout<<rear-front<<endl; // rear=5 , front=0 so 5-0=5 elements cout<<"elements are\n"; for(int i=front;i<rear;i++) cout<<queue[i]<<endl; } else { int length; length=(index-front)+rear; cout<<"total number of elements in queue are:"; cout<<length<<endl; cout<<"elements are\n"; for(int i=front;i<index;i++) for(int j=0;j<rear;j++) cout<<queue[1]<<endl; } } ////////////////////////////////////////////////////////////////// void deletequeue() { if(front==-1&&rear==-1) cout<<"queue not created\n"; else front=-1; rear=-1; cout<<"queue is successfully deleted\n"; } ///////////////////////////////////////////////////////////////// void clearqueue() { if(front==-1&&rear==-1) cout<<"queue not created\n"; else front=0; rear=0; cout<<"queue is successfully cleared\n"; } //////////////////////////////////////////////////////////////// void find() { int temp=0; int number; int i; if(front==-1&&rear==-1) cout<<"queue not created\n"; else cout<<"enter number to find in queue\n"; cin>>number; for(i=front;i<rear;i++) { if(queue[i]==number) { cout<<"number found at position"<<i<<endl; temp=1; } } if(temp==0) cout<<"number not found\n"; } ////////////////////////////////////////////////////////////// void enqueue(int a) { queue[rear]=a; rear=(rear+1)%index; cout<<"element is successfully enqueued\n"; } ////////////////////////////////////////////////////////////// int dequeue() { int a=queue[front]; front=(front+1)%index; return a; } //////////////////////////////////////////////////////////// int isfull() { if(rear-front==rear) return 1; else return 0; } /////////////////////////////////////////////////////////// int isempty() { if(front==rear) return 1; else return 0; } /////////////////////////////////////////////////////////////// int main() { menu(); return 0; }
C++ source code output:

Sample input output
queue project menu
menu output selection
if we select option 1 and enter 1, 2, 3 then option 2 we have
queue display c++ project
display queue c++ project
find more projects here: C++ projects source code

Read More...