circularqueue.c~

来自「这是一个进程通信和手机数据处理程序, 与以前发的手机界面一起构成一个简单手机系」· C~ 代码 · 共 85 行

C~
85
字号
#include "MySHM.H"#define MAXVAL  100 /* Definition of circular queue's struct */typedef struct{ 	int   d[MAXVAL]; 	int   front; 	int	rear; }CirQUEUE;  CirQUEUE cQ_InBox,cQ_OutBox; /* Initial the empty circular queue */void INITQUEUE( SOURCETYPE sType ) {	if( sType == INBOX )	{		cQ_InBox.front = cQ_InBox.rear = MAXVAL-1;	}	else if( sType == OUTBOX)	{		cQ_OutBox.front = cQ_OutBox.rear = MAXVAL-1;	}}/* Data element Enter the circular queue */int ENQUEUE ( SOURCETYPE sType, int element ){ 	if( sType == INBOX)	{		if ( cQ_InBox.front == (cQ_InBox.rear+1) % MAXVAL ) //Fail to enter for the full queue			return 0;		else					     //Successfully enter the queue		{ 			cQ_InBox.rear = (cQ_InBox.rear+1) % MAXVAL; 			cQ_InBox.d[cQ_InBox.rear] = element;   			return 1 ; 		}	}	else if( sType == OUTBOX)	{		if ( cQ_OutBox.front == (cQ_OutBox.rear+1) % MAXVAL ) //Fail to enter for the full queue			return 0;		else					     //Successfully enter the queue		{ 			cQ_OutBox.rear = (cQ_OutBox.rear+1) % MAXVAL; 			cQ_OutBox.d[cQ_OutBox.rear] = element;   			return 1 ; 		}		} }/* Get the Data element from circular queue */int DEQUEUE( SOURCETYPE sType ){ 	if( sType == INBOX)	{		if( cQ_InBox.front == cQ_InBox.rear ) 		//Fail to get data for the empty queue			return 0;		else		{ 			cQ_InBox.front = ( cQ_InBox.front+1) % MAXVAL ;			printf( "Dequeue %d\n",cQ_InBox.d[cQ_InBox.front] );			return ( cQ_InBox.d[cQ_InBox.front] ) ;		}	}	else if( sType == OUTBOX)	{		if( cQ_OutBox.front == cQ_OutBox.rear ) 		//Fail to get data for the empty queue			return 0;		else		{ 			cQ_OutBox.front = ( cQ_OutBox.front+1) % MAXVAL ;			printf( "Dequeue %d\n",cQ_OutBox.d[cQ_OutBox.front] );			return ( cQ_OutBox.d[cQ_OutBox.front] ) ;		}	}	  	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?