#include<process.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>

class MyQueue
{
	private:
		char ch[5][7];
		int head, tail;
	public:
		MyQueue();
		void enqueue(char *);
		void print();
		char * dequeue();
		char *shiftleft();
		void search(char *);
		void update(char *);
};

MyQueue::MyQueue()
{
	head=0,tail=0;
}

void MyQueue::enqueue(char * data)
{
	if(tail<0)
	{
		cout<<"queue is empty...."<<endl;
	}
	else if(tail>=5)
	{
		cout<<"queue is full......";
	}
	else
	{
		strcpy(ch[tail++],data);
	}
}

char* MyQueue::dequeue()
{
	if(tail<0)
	{
		cout<<"\n  queue is empty...."<<endl;
	}
	else
	{

	       shiftleft();
	}
}

char* MyQueue::shiftleft()
{
	if(tail>=0)
	{
	cout<<"\n  DeQueued... : "<<ch[head];
	int i=0;

	while(i!=tail)

		{
			strcpy(ch[i++],ch[i+1]);
			cout<<"\n\n  shifted string is: "<<ch[i];
		}
	tail--;
	cout<<"\n\n   string at left is: "<<ch[head];
	}
	else
	{
	cout<<"queue is empty.....\n";
	}
}
void MyQueue::print()
{

	gotoxy(2,2);
	  cout<<"enter choice........."<<endl;
	  cout<<"[1].EnQueue"<<endl;
	  cout<<"[2].Dequeue"<<endl;
	  cout<<"[3].search"<<endl;
	  cout<<"[4].update"<<endl;	
	  cout<<"[5].exit"<<endl;
}

void MyQueue::search(char *sch)
{

	for(int j=0,k=0;j<5;j++)
	{
		int check;
		check=strcmp(sch,ch[j]);
		if(check==0)
		{
			cout<<"\nsearched string "<<sch<<" is at index "<<j<<endl;
			k=j;
		}
		else
		{
		     cout<<"\nsorry...searched string not found at index: "<<j<<endl;
		}
	}
}

void MyQueue::update(char* sch)
{
	for(int j=0,k=0;j<5;j++)
	{
		int check;
		char temp[7];
		check=strcmp(sch,ch[j]);
		if(check==0)
		{
			cout<<"\n enter a string to update: "<<endl;
			gets(temp);
			strcpy(ch[j],temp);
		}
		else
		{
		     cout<<"\nsorry...searched string not found at index"<<j<<endl;
		}
	}

}



int main()
{
	clrscr();
	MyQueue obj;
	int ch;
	while (1)
	{

	  obj.print();
	  cin>>ch;

	switch(ch)
	{
		case 1:
		clrscr();
		obj.print();
		char ch[10];
		cout<<"enter string to enqueue: ";
		gets(ch);
		obj.enqueue(ch);
		clrscr();
		obj.print();

		break;

		 case 2:
		  clrscr();
		  obj.print();
		  gotoxy(45,10);
		  obj.dequeue();
		  break;

		  case 3:
		  clrscr();
		  obj.print();
		  gotoxy(45,14);
		  char sch[10];
		  cout<<"enter string to search: ";
		  gets(sch);
		  obj.search(sch);
		  break;

		  case 4:
		  clrscr();
		  obj.print();
		  cout<<"enter string to search: ";
		  gets(sch);
		  obj.update(sch);
		  break;

		  case 5:
		  exit(0);
		  break;

	}
  }

	getch();
	return 0;

}
