S
sandy
I am working on an assignment which is a 'discrete event simulation'. I
have a class called event, I need to add it to a priority queue and I
cannot for some reason. I am sure it's the syntax...
Basically I am going to loop through 100 times and create events, first
they go to the priority Queue, then as the time for the event happens I
will move them to 'regular' queues. I can't insert into my Priority
queue.
Here is the header for the Priority Queue:
<code>
#ifndef PQUEUEBH_HPP
#define PQUEUEBH_HPP
// Priority Queue: Header File
template <class Etype>
// Assumption: Etype is defined on the operation <
class PQueue
{
public:
// Constructor
//
// Input : None
// Purpose: To create an empty Priority Queue
// Output : None
PQueue ( );
// Copy constructor I
//
// Input : Priority Queue PQ
// Purpose: To initialize Priority Queue to PQ
// Output : None
PQueue ( const PQueue & PQ );
// Copy constructor II
//
// Input : Array A of length n
// Purpose: To initialize Priority Queue to the elements of A
// Output : None
PQueue ( Etype A[], int n );
// Destructor
//
// Input : None
// Purpose: To free memory of Priority Queue
// Output : None
~PQueue ( );
// Copy assignment
//
// Input : Priority Queue PQ
// Purpose: To assign PQ to current Priority Queue
// Output : Current Priority Queue
const PQueue & operator= ( const PQueue & PQ );
// Insert
//
// Input : Element E
// Purpose: To place E into the Priority Queue
// Output : 1 if successful; 0 otherwise
int Insert ( const Etype & E );
// DeleteMin
//
// Input : None
// Purpose: To return the highest priority element E and
// To delete E from the Priority Queue
// Output : Element E and 1 if successful; 0 otherwise
int DeleteMin ( Etype & E );
// Length
//
// Input : None
// Purpose: To the return the current size of the Priority Queue
// Output : Current size of Priority Queue
int Length ( ) const;
// Empty
//
// Input : None
// Purpose: To check if Priority Queue is empty
// Output : 1 if empty; 0 otherwise
int Empty ( ) const;
// Clear
//
// Input : None
// Purpose: To re-initialize Priority Queue to empty
// Output : None
void Clear ( );
// Overloaded ==
int operator== ( const PQueue & PQ ) const;
private:
// DoubleArray
//
// Input : None
// Purpose: To double the maximum size of Priority Queue
// Output : None
void DoubleArray ( );
// FixHeap
//
// Input : None
// Purpose: To restore the heap-order property
// of the binary heap
// Output : None
void FixHeap ( );
// PercolateDown
//
// Input : Position i
// Purpose: To restore the heap-order property
// of the binary heap rooted at position i
// Output : None
void PercolateDown ( int i );
// PercolateUp
//
// Input : Position i
// Purpose: To restore the heap-order property
// of the binary heap along the path from i to the root
// Output : None
void PercolateUp ( int i );
// Data Members
// Current and maximum size of Priority Queue
int CurrentSize, MaxSize;
// Dynamic binary heap to store the elements of Priority Queue
Etype *Array;
};
#endif
</code>
here is my function where I am creating an event and trying to insert
it:
<code>
void RunSim()
{
typedef Queue<Event> Q1, Q2, Q3, Q4;
typedef PQueue<Event> PQ;
Event *E;
// put the first Arrival into the PQ
E = new Event;
// interval is 1 to 5 params: Event Number, Time (int), Type A or C
E->LoadEvent(0, GenRandom(5), 'A');
PQ.Insert(E);
}
</code>
I keep getting told that it expects a semi-colon before the
PQ.Insert(E);
If I comment out that line it compiles and runs, so the semi-colon is
not the problem; but I have no idea what is...
The more I program with C++ the more I like vb.net...
I am hoping it's something stupid simple that just needs another pair
of eyes.
Thanks for your assistance.
have a class called event, I need to add it to a priority queue and I
cannot for some reason. I am sure it's the syntax...
Basically I am going to loop through 100 times and create events, first
they go to the priority Queue, then as the time for the event happens I
will move them to 'regular' queues. I can't insert into my Priority
queue.
Here is the header for the Priority Queue:
<code>
#ifndef PQUEUEBH_HPP
#define PQUEUEBH_HPP
// Priority Queue: Header File
template <class Etype>
// Assumption: Etype is defined on the operation <
class PQueue
{
public:
// Constructor
//
// Input : None
// Purpose: To create an empty Priority Queue
// Output : None
PQueue ( );
// Copy constructor I
//
// Input : Priority Queue PQ
// Purpose: To initialize Priority Queue to PQ
// Output : None
PQueue ( const PQueue & PQ );
// Copy constructor II
//
// Input : Array A of length n
// Purpose: To initialize Priority Queue to the elements of A
// Output : None
PQueue ( Etype A[], int n );
// Destructor
//
// Input : None
// Purpose: To free memory of Priority Queue
// Output : None
~PQueue ( );
// Copy assignment
//
// Input : Priority Queue PQ
// Purpose: To assign PQ to current Priority Queue
// Output : Current Priority Queue
const PQueue & operator= ( const PQueue & PQ );
// Insert
//
// Input : Element E
// Purpose: To place E into the Priority Queue
// Output : 1 if successful; 0 otherwise
int Insert ( const Etype & E );
// DeleteMin
//
// Input : None
// Purpose: To return the highest priority element E and
// To delete E from the Priority Queue
// Output : Element E and 1 if successful; 0 otherwise
int DeleteMin ( Etype & E );
// Length
//
// Input : None
// Purpose: To the return the current size of the Priority Queue
// Output : Current size of Priority Queue
int Length ( ) const;
// Empty
//
// Input : None
// Purpose: To check if Priority Queue is empty
// Output : 1 if empty; 0 otherwise
int Empty ( ) const;
// Clear
//
// Input : None
// Purpose: To re-initialize Priority Queue to empty
// Output : None
void Clear ( );
// Overloaded ==
int operator== ( const PQueue & PQ ) const;
private:
// DoubleArray
//
// Input : None
// Purpose: To double the maximum size of Priority Queue
// Output : None
void DoubleArray ( );
// FixHeap
//
// Input : None
// Purpose: To restore the heap-order property
// of the binary heap
// Output : None
void FixHeap ( );
// PercolateDown
//
// Input : Position i
// Purpose: To restore the heap-order property
// of the binary heap rooted at position i
// Output : None
void PercolateDown ( int i );
// PercolateUp
//
// Input : Position i
// Purpose: To restore the heap-order property
// of the binary heap along the path from i to the root
// Output : None
void PercolateUp ( int i );
// Data Members
// Current and maximum size of Priority Queue
int CurrentSize, MaxSize;
// Dynamic binary heap to store the elements of Priority Queue
Etype *Array;
};
#endif
</code>
here is my function where I am creating an event and trying to insert
it:
<code>
void RunSim()
{
typedef Queue<Event> Q1, Q2, Q3, Q4;
typedef PQueue<Event> PQ;
Event *E;
// put the first Arrival into the PQ
E = new Event;
// interval is 1 to 5 params: Event Number, Time (int), Type A or C
E->LoadEvent(0, GenRandom(5), 'A');
PQ.Insert(E);
}
</code>
I keep getting told that it expects a semi-colon before the
PQ.Insert(E);
If I comment out that line it compiles and runs, so the semi-colon is
not the problem; but I have no idea what is...
The more I program with C++ the more I like vb.net...
I am hoping it's something stupid simple that just needs another pair
of eyes.
Thanks for your assistance.