-
Enqueue
How would i change this to were it puts the elements in priority order? with the highest priority at the front. Thanx.
void ENQUEUE(queue *Q,ElementType X)
/* insert the element X at the front of queue Q */
{
if Q->size == max_size /*check the array is full */
ERROR("array is full"); /* print warning message */
else
{ /*insert the element at the front of the queue */
Q->rear = (Q->rear + 1)%max_size; /*move rear 1 clockwise*/
Q->entry[Q->rear] = X; /*insert element at rear*/
Q->size ++;
}
}
-
> void ENQUEUE(queue *Q,ElementType X)
> /* insert the element X at the front of queue Q */
> {
You should check to see that Q actually exists first.
if( !Q )
{ ERROR("Q is NULL."); return; }
> if Q->size == max_size /*check the array is full */
You should have parenthesis around this.
if( Q->size == max_size )
This is wrong. Why yould you...
> ERROR("array is full"); /* print warning message */
> else
> { /*insert the element at the front of the queue */
> Q->rear = (Q->rear + 1)%max_size; /*move rear 1 clockwise*/
> Q->entry[Q->rear] = X; /*insert element at rear*/
> Q->size ++;
> }
> }
...increment the Q size if your array is full?
{ ERROR("Q is full."); return; }
Q->rear = ( Q->rear + 1 ) % max_size; /* do whatever */
Q->entcy[Q->rear] = X; /* do whatever */
Q->size++; /* do whatever */
}
You need to really learn how to use parenthesis and braces effectivly.
Quzah.