Question: *********IN C++********* I need the following methods completed: I need Duplicates logic changed up a bit, it should take the item thats first in the

*********IN C++*********

I need the following methods completed:

I need Duplicates logic changed up a bit, it should take the item thats first in the queue, duplicate it, and put it in the front of the queue.

int Mul(void) needs to be completed: it multiplies the first two items in the queue and inserts the product in the front of the queue. return 0 if success, return -79 if there are not at least two items in the queue, return -81 if it would cause a queue overflow. -82 needs to be returned if the result of multiplying would cause a duplicate.

int reverse(void): reverses all the items in the queue. the first item becomes the last item and so on, returns a 0 if successful.

int peek(int& num): gets the first item, places it in num without removing it from the queue return 0 if success and -88 if it fails.

if you need a test driver i have one just let me know.

#include

#include "queue.h"

using namespace std;

static int nums[10];

int front = 0, sizeOfArray = 0;

int initialCapacity = 10, rear = initialCapacity - 1;

int Enqueue(int num) {

if (sizeOfArray == initialCapacity) {

return -58;

}

for (int i = 0; i < initialCapacity; i++) {

if (nums[i] == num) {

return -62;

}

else {

rear = (rear + 1) % initialCapacity;

nums[rear] = num;

sizeOfArray++;

return 0;

}

}

}

int Dequeue(int& num) {

if (sizeOfArray == 0) {

return -64;

}

front = (front + 1) % initialCapacity;

sizeOfArray--;

return 0;

}

int isEmpty() {

if (sizeOfArray == 0) {

return 1;

}

else {

return 0;

}

}

int Exists(int num) {

for (int i = 0; i < sizeOfArray; i++) {

int index = (front + i) % sizeOfArray;

if (nums[index] == num) {

return 1;

}

else {

return 0;

}

}

return 0;

}

void Clear(void) {

front = rear = sizeOfArray = 0;

}

void Print(void) {

for (int i = 0; i < sizeOfArray; i++) {

cout << nums[i] << " ";

}

cout << endl;

}

int Duplicate(void) {

if (sizeOfArray == 0) {

return -78;

}

if (sizeOfArray == initialCapacity) {

return -81;

}

int dupeNum;

dupeNum = nums[front];

sizeOfArray++;

int temp = nums[front], x, i = front;

while (i < sizeOfArray) {

x = nums[i];

nums[i] = temp;

temp = x;

i++;

}

return 0;

}

int Mul(void) {

}

int Reverse(void) {

}

int Peek(int& num){

}

its fine, i dont mind but I need it dont as soon as possible. do you need the test driver?

is that a yes?

i need the mul function written, the reverse function written, and i need the peek function written. i need you to double check(debug) to make sure that the program works as intended to.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!