Can anyone explain or solve this question? It\'s a C++ data structures question
ID: 3850018 • Letter: C
Question
Can anyone explain or solve this question?
It's a C++ data structures question
a) Complete the code below of a Replace() member function for the circular array based queue class, so that post-conditions are satisfied. Your code should not use other QueueType member functions. void QueueType:: Replace(ItemType item, ItemType newItem) {//Pre: The dynamic array based queue is initialized.//Post: If the queue is empty, UNDERFLOW is returned: else every//occurrence of item in the queue has been replaced by newItem. if () return UNDERFLOW: int n = 0;//number of items processed//index to the current item while () { if (queueitems [index] == item)Explanation / Answer
void QueueType::Replace(ItemType item, ItemType newItem) {
if(front == -1) {
return UNDERFLOW;
}
int n=0;
int index = front; // index to the current item
// Process items
while(n < SIZE) {
if(queueItems[index] == item) {
queueItems[index] = newItem;
}
// increment index to point to next item
index = (index + 1) % SIZE;
// keep counting number of items processed
n++;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.