Working with Enqueue/Dequeue

Hello guys, I am looking for some help and some reassurance if I am on the right track. I am most likely not, which is what I think. First thing I would like for you guys to check my code if I wrote everything correctly inside the functions. Second, I really don't know what to write inside the Function "Front()". Which is where I am stuck on so far.

Everything I have so far inside the functions is what I got and understood from the book I was assigned. I notice in online examples there is a pointer happening inside dequeue and enqueue. I couldn't really build off the online examples since many of them use a variable called next and their enqueue and dequeue are boolean functions. So I need specific advice.



Last edited on
Please, some help would be appreciated.
.cpp:
line 11: You're declaring an array here that goes out of scope (disappears) when the constructor exits.

lines 9-10: You're initializing front and back to 10. It would make more sense to initialize them to 0 to indicate your array is empty.

Line 17: You're using the assignment operator (=), not the equality operator (==).

Line 29: Your prompt is wrong.

Line 43: newitem goes out of scope when Dequeue exists and is lost.

Line 60: You want to return passengers[front], assuming you have at least one entry in your array.

Thanks for the reply! . So far I have fixed most of thing you have mentioned. Except in line 43, I'm not sure how I will be doing all of it correctly.


Only method I could think of right now is


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void CQueue::Dequeue(Passenger& newitem) //making it a parameter and passing it by reference
{
	

	if (IsEmpty)
	{
		cout << "Queue is Empty" << endl;
	}
	else
	{
		front = (front + 1) % MAX;
		newitem = passengers[front];
		
	}



}



Sadly, the professor doesn't like when we change the code. When I also just state

Passenger& newitem;
inside the function, I get an error saying. newitem requires an initializer.
Still in need of some help. I still can't find a solution to my Dequeue function. Also my enqueue function is also not working when I run the entire program.
Topic archived. No new replies allowed.