i need help in making the size of the array to n size in queues.i have made a program help me in it.

////##############/////
#include <iostream>

using namespace std;

#define MAX 5           


class queue
{
 private:
 	int t[MAX];
 	int al;      
 	int dl;      

 public:
  queue()
  {
  	dl=-1;
  	al=-1;
  }

  void remove()
  {
     int tmp;
     if(dl==-1)
     {
	    cout<<"underflow Queue";
     }
     else
     {
		for(int j=0;j<=al;j++)
		{
	  		if((j+1)<=al)
	  		{
	  			tmp=t[j+1];
	  			t[j]=tmp;
	  		}
	  		else
	  		{
	  			al--;

	  		if(al==-1)
		 		dl=-1;
		 	else
		 		dl=0;
	  		}
		}
     }
  }

void insert(int item)
{
 	if(dl==-1 && al==-1)
 	{
  		dl++;
  		al++;
 	}
   else
   {
  		al++;
  		if(al==MAX)
   	{
			cout<<"overflow Queue\n";
			al--;
			return;
  		}
 	}
 	t[al]=item;

}

  void display()
  {
  	if(dl!=-1)
   {
   	for(int iter=0 ; iter<=al ; iter++)
      	cout<<t[iter]<<" ";
   }
   else
   	cout<<"EMPTY";
  }

};

int main()
{
 queue a;
 int data[5]={32,23,45,99,24};

 cout<<"Queue before inserting Elements: ";
 a.display();
 cout<<endl<<endl;

 for(int iter = 0 ; iter < 5 ; iter++)
 {
   a.insert(data[iter]);
   cout<<"inserting Number : "<<(iter+1)<<" : ";
   a.display();
   cout<<endl;
 }
 cout<<endl;
 cout<<"Queue after inserting Elements: ";
 a.display();
 cout<<endl<<endl;

 for(iter=0 ; iter < 5 ; iter++)
 {
   a.remove();
   cout<<"removing Number : "<<(iter+1)<<" : ";
   a.display();
   cout<<endl;
 }
 return 0;
}

i am sorry i didnot get the idea do you want to convert the static array to dynamic one or what?

Explain in details how your program works. Did you find any error?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.