Change Queue Size

Is there a way to change the size of a particular queue to be different than others? I'm using const int maxqueue = 5; for 3 queues but I want a 4th to be maxqueue 15. Thanks.
It's certainly possible. What are the specifics of your code?
#include <iostream>
#include <fstream>
using namespace std;

const int maxqueue = 5;
class queue_type
{
public:
	void clear_queue();
	bool empty_queue();
	bool full_queue();
	void insert_queue(int numb);
	void delete_queue(int& numb);
	int queue[6];
	int front, rear;
};
	queue_type a, b, c, d;


What I'm trying to do is pop queues a, b, and c (which are size 5) to queue d (which will be 15). Then I will insert queue d split up back into a, b, c, but remove a a number from d if the user instructs it to do so while it's filling a, b, c.
Use [code] tags, not [output] or whatever - then you get syntax highlighting :p

Hmm... Can I see the code where you use maxqueue?
Here's the entire program so far:

/*This is the PRIMARY FILE for the garage project.
=============================================================*/

#include <iostream>
#include <fstream>
using namespace std;

const int maxqueue = 5;
class queue_type
{
public:
	void clear_queue();
	bool empty_queue();
	bool full_queue();
	void insert_queue(int numb);
	void delete_queue(int& numb);
	int queue[6];
	int front, rear;
};
	queue_type a, b, c, d;

//=============================================================

int main()
{
	int x = 0;
	int q = 0; //temp value for queue popping
	int h = 0; //counter for departing while loop
	char n; //n is arrive, depart, or exit;  x is numb number
	a.clear_queue();
	b.clear_queue();
	c.clear_queue();
	d.clear_queue();

	//=============================================================
	// STARTUP CODE
	//=============================================================
	cout << "               Is a vehicle arriving or departing?\n" << endl;
	cout << "Car Arriving : A   ||   Car Departing : D   ||   Exit : X" << endl;
	cout << "Enter selection letter ==> ";
	cin >> n;

	if ((!(n=='x')) && (!(n=='X')) && (!(n=='a')) && (!(n=='A')) && (!(n=='d')) && (!(n=='D')))
	{
		cout << "    Invalid entry. \n" << endl;
		cout << "Enter selection letter ==> ";
		cin >> n;
	}

	if ((!(n=='x')) && (!(n=='X')))
	{
			cout << "\nEnter a license number ==> ";
			cin >> x;
	}
	//=============================================================
	// ARRIVE CODE
	//=============================================================
	while ((n=='a') || (n=='A'))
	{
	if (!(a.full_queue()))
	{
		a.insert_queue(x);
		cout << "Vehicle has been parked in garage A." << endl;
		cout << "Car Arriving : A   ||   Car Departing : D   ||   Exit : X" << endl;
		cout << "Enter selection letter ==> ";
		cin >> n;
			if ((n=='a') || (n=='A'))
			{
				cout << "\nEnter a license number ==> ";
				cin >> x;
			}
	}
	else if (!(b.full_queue()))
	{
		b.insert_queue(x);
		cout << "Garage A is full.  Vehicle has been parked in garage B." << endl;
		cout << "Car Arriving : A   ||   Car Departing : D   ||   Exit : X" << endl;
		cout << "Enter selection letter ==> ";
		cin >> n;
			if ((n=='a') || (n=='A'))
			{
				cout << "\nEnter a license number ==> ";
				cin >> x;
			}
	}
	else if (!(c.full_queue()))
	{
		c.insert_queue(x);
		cout << "Both garages are full.  Vehicle has been parked on the street." << endl;
		cout << "Car Arriving : A   ||   Car Departing : D   ||   Exit : X" << endl;
		cout << "Enter selection letter ==> ";
		cin >> n;
			if ((n=='a') || (n=='A'))
			{
				cout << "\nEnter a license number ==> ";
				cin >> x;
			}
	}
	}//End while

	//=============================================================
	// DEPART CODE
	//=============================================================
	while ((n=='d') || (n=='D')) //n is decision, x is plate number
	{
		//working on this

	}

	//=============================================================
	// EXIT CODE
	//=============================================================
	if ((n=='x') || (n=='X')) 
		cout << "This is temporary code, showing that the program has ended." << endl;
	return 0;
}

//=============================================================
void queue_type::clear_queue()
{
	front = maxqueue;
	rear = maxqueue;
}
//=============================================================
bool queue_type::empty_queue()
{
	if (rear == front)
		return true;
	else
		return false;
}
//=============================================================
bool queue_type:: full_queue()
{
	int querear;
	if (rear == maxqueue)
		querear = 0;
	else
		querear = rear + 1;
	if (querear == front)
		return true;
	else
		return false;
}
//=============================================================
void queue_type::insert_queue(int numb)
{
	if (rear == maxqueue)
		rear = 0;
	else
		rear = rear + 1;
	queue[rear] = numb;
}
//=============================================================
void queue_type::delete_queue(int& numb)
{
	if (front == maxqueue)
		front = 0;
	else
		front = front + 1;
	numb = queue[front];
}
//=============================================================
Last edited on
I have only read some of your code, but have you considered making queue_type a template class?
1
2
3
template <int MaxQueue> class queue_type {
// etc
};


Bear in mind that there is also a type std::queue in the C++ Standard Template Library :p
Topic archived. No new replies allowed.