How do you delete the front cell of an array in an array based circular queue?

Here's the Queue cpp functions

#include <iostream>
#include <string>
#include "Contributor.h"
#include "myQueue.h"
using namespace std;

myQueue::myQueue()
	{
	         front=0;
		rear =0;
		Index=0;
		size= 0;
		ArrayQ[10];
	}


myQueue::myQueue(const myQueue &CCmyQueue)
{	
	for(int i=0;i < CCmyQueue.Index;i++)
		{			
			ArrayQ[i]=CCmyQueue.ArrayQ[i]; 
			front= CCmyQueue.front;
			rear =CCmyQueue.rear;
			Index=CCmyQueue.Index;
			size =CCmyQueue.size;
		}
}


myQueue &myQueue:: operator =(const myQueue & RHS) 
{
if(this!= &RHS)
	{
	  for (int i=0; i<RHS.Index;i++)
	  {
		ArrayQ[i]= RHS.ArrayQ[i];
		Index = RHS.Index;
		rear= RHS.rear;
		front= RHS.front;
		size= RHS.size;
	  }
	}
return *this;
}


myQueue::~myQueue()
{
cout<< "default D-Tor"<<endl;
}


bool myQueue::enQueue(Contributor InData)
{
	if(IsFull())
		{
			cout<< " Queue is full"<<endl;
			return false;
	         }
           else
                 {
			ArrayQ[rear]=InData;
			step(rear);
			Index++;
	        }
	cout<<"Index ="<<Index<<endl;
	return true;
}


bool myQueue::deQueue()
{
	if(IsEmpty())
	    {
			cout<<"the IsEmpty()"<< endl;
	    }
         else
          {
			//code for deleting the front data?
			step(front);
			--Index;
	}
return true;
}


bool myQueue::IsFull()
{
	if(Index==MAXSIZE)
		{
		return true;
		}
		return false;
}


bool myQueue::IsEmpty()
{
	if(Index==0)
	{
	     return true;
	}
	     return false;
}

void myQueue::step(int &num)
{
	if(num==(size-1))
	  {
	         num=0;
	  }
           else
            {
	        num++;
            }
}
void myQueue::ShowFront()
{
	cout<<"this is the Front Object"<<endl;
	cout<<ArrayQ[front]<<endl;
}

void myQueue::ShowRear()
{
	cout<<"this is the Rear Object "<<endl;
	cout<<ArrayQ[rear-1]<<endl;
}

void myQueue::PrintQ()
{
	for (int i=0;i<Index;++i)
	{
	        cout<<ArrayQ[i];
	}
}

The problem may be in my print function as well. I have it printing using the index, so it doesn't print out empty elements. Now I'm trying to delete the front element in the code above, and it appears to be working until I print the queue.

When I print the queue, the supposedly deleted element prints out, but the last element does not. I've attached all the functions if it will help.

I think you maybe misunderstand the meaning of index and size. There are some errors in your code, please see my comments below. I attached my code, which is base on yours. Please refer to it.

How do you delete the front cell of an array in an array based circular queue?

Here's the Queue cpp functions

#include <iostream>
#include <string>
#include "Contributor.h"
#include "myQueue.h"
using namespace std;

myQueue::myQueue()
	{
	         front=0;
		rear =0;
		Index=0;
		size= 0;
		ArrayQ[10];  //what does this mean? I think it's not necessary
	}


myQueue::myQueue(const myQueue &CCmyQueue)
{	
	for(int i=0;i < CCmyQueue.Index;i++)
		{			
			ArrayQ[i]=CCmyQueue.ArrayQ[i]; 
// you should get the following four lines out of this loop
			front= CCmyQueue.front;
			rear =CCmyQueue.rear;
			Index=CCmyQueue.Index;
			size =CCmyQueue.size;
		}
}


myQueue &myQueue:: operator =(const myQueue & RHS) 
{
if(this!= &RHS)
	{
	  for (int i=0; i<RHS.Index;i++)
	  {
		ArrayQ[i]= RHS.ArrayQ[i];
// the same as in the copy constructor 
		Index = RHS.Index;
		rear= RHS.rear;
		front= RHS.front;
		size= RHS.size;
	  }
	}
return *this;
}


myQueue::~myQueue()
{
cout<< "default D-Tor"<<endl;
}


bool myQueue::enQueue(Contributor InData)
{
	if(IsFull())
		{
			cout<< " Queue is full"<<endl;
			return false;
	         }
           else
                 {
			ArrayQ[rear]=InData;
			step(rear);
			Index++;
	        }
	cout<<"Index ="<<Index<<endl;
	return true;
}


bool myQueue::deQueue()
{
	if(IsEmpty())
	    {
			cout<<"the IsEmpty()"<< endl;
	    }
         else
          {
			//code for deleting the front data?
			step(front);
			--Index;
	}
return true;
}


bool myQueue::IsFull()
{
	if(Index==MAXSIZE)
		{
		return true;
		}
		return false;
}


bool myQueue::IsEmpty()
{
	if(Index==0)
	{
	     return true;
	}
	     return false;
}

void myQueue::step(int &num)
{
	if(num==(size-1))
	  {
	         num=0;
	  }
           else
            {
	        num++;
            }
}
void myQueue::ShowFront()
{
	cout<<"this is the Front Object"<<endl;
	cout<<ArrayQ[front]<<endl;
}

void myQueue::ShowRear()
{
	cout<<"this is the Rear Object "<<endl;
	cout<<ArrayQ[rear-1]<<endl;
}

void myQueue::PrintQ()
{
	for (int i=0;i<Index;++i)
	{
	        cout<<ArrayQ[i];
	}
}

okay, I understand most of what you've done, what does including the windows.h file give me? I've never used it before

okay, I understand most of what you've done, what does including the windows.h file give me? I've never used it before

I just glanced at littlestone's code, so I'm not sure whether you need windows.h to use it. I didn't see anywhere at first glance where you needed it, which doesn't mean that i couldn't have missed something. Try compiling with and without that #include line. Delete it if it makes no difference. windows.h is Windows-specific. Unless there's something in this assignment where you NEED to only have it work on Windows, and it doesn't appear to me that there is, don't use windows.h.

http://en.wikipedia.org/wiki/Windows.h

Thanks for the heads up Vernon. BTW I figured out the linked list thing thanks to your tips on the node class and how data was being passed in.

Sorry for troubling you with the windows.h. I included it just for using Sleep function to debug your code. After debugging I deleted the Sleep function but forgot to delete the windows.h.

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.