/*_##################################### #######################################
_##
### Queue implemented by static Array
_ ## Author: xwlee
_ ## Time: 2006.12.31
### Chang'an University
_ ## Development condition: win2003 SERVER + vc6.0
_##
_ ## Static_array.cpp File
_####################################### ###################################*/
# Include "Stack. H"
# Include <stdio. h>
# Define queue_size 5 // maximum number of elements in the queue
// # Define array_size (queue_size) // The length of the array
# Define array_size (queue_size + 1) // array length (method 2)
// It is used to store arrays of queue elements and pointers to queue headers and tails.
Static queue_type queue [array_size];
Static size_t front = 1;
Static size_t rear = 0;
Static size_t qnumber = 0; // introduce a new variable to record the number of elements in the queue (method 1)
// Create_stack Function
Int create_stack (size_t size)
{
Return 1;
}
// Destroy_stack Function
Int destroy_stack (void)
{
Return 1;
}
// Insert Function
Void myinsert (queue_type value)
{
If (is_full ())
{
Printf ("queue is already full, insert is false./N ");
Exit (0 );
}
Rear = (Rear + 1) % array_size;
Queue [rear] = value;
Printf ("Rear = % d", rear );
Qnumber ++; // introduce new variables. (method 1)
}
// Delete function
Void mydelete (void)
{
If (is_empty () // If the queue is empty, the condition is true.
{
Printf ("queue already empty, delete is false./N ");
Exit (0 );
}
Front = (front + 1) % array_size;
Printf ("front = % d", front );
Qnumber --; // introduce new variables. (method 1)
}
// First Function
Queue_type first (void)
{
If (is_empty () // If the queue is empty, the condition is true.
{
Printf ("queue already empty./N ");
Exit (0 );
}
Return queue [Front];
}
// Is_empty Function
Int is_empty (void)
{
Return (Rear + 1) % array_size = front;
// Return qnumber = 0; // introduce new variables.
}
// Is_full Function
Int is_full (void)
{
Return (Rear + 2) % array_size = front;
// Return qnumber = array_size; // introduce new variables.
}