⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 circularqueue.c

📁 这是一个进程通信和手机数据处理程序, 与以前发的手机界面一起构成一个简单手机系统,是我们做的第一个版本,供大家一起学习
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -