Priority Queue

I have a priority queue which I populate. Another function will pop its first entry, calculate a departure time and push it into the priority queue. I follow these steps in the debugger and everything looks correct. Then, as soon as the priority queue gets back to the calling function everything that just happened disappears, and the priority queue is back to its original state. Can anyone explain why that is happening, and how to keep the changes I made?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48


	// Event loop 
	while (!eventListPQueue.empty()) {                           // Event list is not empty

		newEvent = eventListPQueue.top();
		currentTime = newEvent.arrivalTime;                      // Get current time       

		if (newEvent.arrivalTime && newEvent.departureTime == 0) {                              // is an arrival event
			processArrival(currentTime, newEvent, eventListPQueue, bankQueue, tellerAvailable);
		}

		else
			processDeparture(newEvent, eventListPQueue, bankQueue, tellerAvailable);
	}






void processArrival(int currentTime, Event newEvent, priority_queue<Event> eventListPQueue, queue<Customer> bankQueue, bool tellerAvailable)
{
	Event grab;
	Event event;
	Event eventCustomer;
	Customer customerIn_line;

	eventListPQueue.pop();                                           // Remove this event from the event list 

	event.customerID++;                                              // customer = customer referenced in arrivalEvent 
	if (bankQueue.empty() && tellerAvailable) {

		grab.departureTime = currentTime + newEvent.transactionTime; //	departureTime = currentTime + transaction time in arrivalEvent       
		grab.newDepartureEvent = grab.departureTime;				 //	newDepartureEvent = a new departure event with departureTime    
		eventListPQueue.push(grab);									 //	eventListPQueue.add(newDepartureEvent)      
		tellerAvailable = false;                                     //	tellerAvailable = false

		

	}
	else {
		customerIn_line.arrivalTime = event.arrivalTime;
		customerIn_line.transactionTime = event.transactionTime;
		bankQueue.push(customerIn_line);                                    //  bankQueue.enqueue(customer) 
	}
}
> void processArrival(int currentTime, Event newEvent, priority_queue<Event> eventListPQueue, queue<Customer> bankQueue, bool tellerAvailable)
If you want the queues to actually change, pass them by reference.

You're just working on local copies, which are then lost when the function returns.
Thank you, that worked.

I thought arrays are automatically passed by reference. I guess that is just c-strings.
Arrays are always passed as a pointer to the first element of the array.

Also, pointers and references are different things in C++.

Also, where are the arrays in that function prototype? I saw no [] or *

Plenty of instances of class objects (passed by value).
Thanks for the clarification.

Sounds like I need to read up on exactly what the STL queue and priority queue classes are. I checked them out briefly on cplusplus.com, but what I was looking at were the member functions associated with them. They appear to be a modification of the vector class.
Topic archived. No new replies allowed.