0

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;
}

Edited by Ezzaral: Added code tags. Please use them to format all code that you post.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Mr. K
0

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

Edited by mazzica1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.