[c]代码库
//置空队
c_SeQueue* Init_SeQueue()
{
q=malloc ( sizeof ( c_SeQueue ) );
q->front=q->rear=MAXSIZE-1;
q->num=0;
return q;
}
//入队
int In_SeQueue ( c_SeQueue *q , datatype x )
{
if ( num==MAXSIZE )
{
printf ( "队满" );
return –1; /*队满不能入队*/
}
else
{
q->rear= ( q->rear+1 ) % MAXSIZE;
q->data[q->rear]=x;
num++;
return 1; /*入队完成*/
}
}
//出队
int Out_SeQueue ( c_SeQueue *q , datatype *x )
{
if ( num==0 )
{
printf ( "队空" ) ;
return –1; /*队空不能出队*/
}
else
{
q->front= ( q->front+1 ) % MAXSIZE;
*x=q->data[q->front]; /*读出队头元素*/
num--;
return 1; /*出队完成*/
}
}
//判队空
int Empty_SeQueue ( c_SeQueue *q )
{
if ( num==0 ) return 1;
else return 0;
}