zoukankan      html  css  js  c++  java
  • 一个小队列,MCU专用

    近几天在做51单片机小车,为了实时记录小车状态,就写了个微型版的队列。贴出来,或许大家也能用得上。

    //////////////////////////////////////////////////////////////////////////
    // Description: micro queue for 51 MCU.
    // Author: xu.
    // Date:2012-7-24.
    //////////////////////////////////////////////////////////////////////////
    
    //#define QCAP 32  // queue capacity. queue swtich.
    #ifdef QCAP
    
    typedef unsigned char  	_Ty; // element type.
    typedef unsigned char  	_St; // size type.
    
    _Ty queue[QCAP]; // queue instance.
    _St size;  // 
    _St i;
    #define ILLEGAL_VAL 0xff; // 非法值.
    
    void initQ(void)
    {
    	size = 0;
    }
    
    _St pushQ(_Ty state)
    {
    	if(size < QCAP) {
    		queue[size++]=state;
    		return 0;
    	}
    	for(i=1; i<QCAP; ++i ) {
    		queue[i-1]=queue[i];					
    	}		
    	queue[QCAP-1]=state;
    	return 1;
    }
    
    _Ty popQ(void)
    {
    	_Ty res;
    	if ( size == 0 ) return ILLEGAL_VAL;
    	res = queue[0];
    	for(i=1; i<size; ++i ) {
    		queue[i-1]=queue[i];					
    	}
    	--size;
    	return res;
    }
    
    _Ty isempty(void)
    {
    	return size == 0;
    }
    
    #endif // QCAP


     

  • 相关阅读:
    Matlab norm 用法小记
    C51存储器类型 MCS51单片机物理存储器区域
    MATLAB 中NORM运用
    Matlab norm 用法小记
    C51存储器类型 MCS51单片机物理存储器区域
    MATLAB 中NORM运用
    poj2031
    poj1039
    poj3122
    poj3980
  • 原文地址:https://www.cnblogs.com/xusw/p/5205872.html
Copyright © 2011-2022 走看看