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


     

  • 相关阅读:
    法正(17):玄德
    法正(16):舌战
    法正(15):卢氏
    法正(14):寿星
    struts2笔记---struts2的执行过程
    Oracle数据库(一)
    flask的使用(一)
    struts2--笔记(一)
    docker基础(二)
    docker安装及问题处理
  • 原文地址:https://www.cnblogs.com/xusw/p/5205872.html
Copyright © 2011-2022 走看看