| | |
Deleting from Array Circular Queue
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 226
Reputation:
Solved Threads: 1
How do you delete the front cell of an array in an array based circular queue?
Here's the Queue cpp functions
Here's the Queue cpp functions
C++ Syntax (Toggle Plain Text)
#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]; } }
Last edited by henpecked1; Aug 28th, 2008 at 1:19 am.
•
•
Join Date: Dec 2007
Posts: 226
Reputation:
Solved Threads: 1
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.
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.
•
•
Join Date: Mar 2008
Posts: 42
Reputation:
Solved Threads: 6
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]; } }
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
•
•
•
•
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
Last edited by VernonDozier; Aug 28th, 2008 at 2:41 pm.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: error LNK2001
- Next Thread: Data Structures
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






