<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[[实践OK] C语言-循环队列的简单实现]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Fri, 07 Aug 2015 03:37:45 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	用C语言实现一个循环队列并不难。关键点在于对队列 &quot;空&quot; 和 &quot;满&quot; 状态的判断。<br/><br/>正如《C和指针》中所描写的，有两种方法来实现对队列空和满状态的判断。<br/><br/>在数组中空一个元素不填，起始时, 置tail为0, front为1, 这样一来, 实现要浪费queue buffer中两个元素空间：<br/>队列空:&nbsp;&nbsp;(tail+1) % queue_size == front<br/>队列满:&nbsp;&nbsp;(tail+2) % queue_size == front<br/>定义一个变量来记录队列中元素的个数, 判断队列的空和满直接看变量的值即可<br/> <br/><br/>本文中使用的是第2种:<br/><textarea name="code" class="C" rows="15" cols="100">
#include &lt;stdio.h&gt;&nbsp;&nbsp;
&nbsp;&nbsp;
#define QUEUE_SIZE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;
#define QUEUE_TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp;
&nbsp;&nbsp;
static int queue_cnt = 0;&nbsp;&nbsp;
static int queue_front = 0;&nbsp;&nbsp;
static int queue_tail = 0;&nbsp;&nbsp;
&nbsp;&nbsp;
static QUEUE_TYPE queue_buf[QUEUE_SIZE];&nbsp;&nbsp;
&nbsp;&nbsp;
int is_empty()&nbsp;&nbsp;
&#123;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return queue_cnt == 0;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;
&nbsp;&nbsp;
int is_full()&nbsp;&nbsp;
&#123;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return queue_cnt == QUEUE_SIZE;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;
&nbsp;&nbsp;
int insert(QUEUE_TYPE e)&nbsp;&nbsp;
&#123;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if (is_full()) &#123;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;queue is full!!!&#92;n&quot;);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;queue_buf[queue_tail] = e;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;queue_tail = (queue_tail + 1) % QUEUE_SIZE;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;queue_cnt++;&nbsp;&nbsp;
&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return 1;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;
&nbsp;&nbsp;
int delete()&nbsp;&nbsp;
&#123;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if (is_empty()) &#123;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;queue is empty!!!&#92;n&quot;);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;queue_front = (queue_front + 1) % QUEUE_SIZE;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;queue_cnt--;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return 1;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;
&nbsp;&nbsp;
int main()&nbsp;&nbsp;
&#123;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;insert(3);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;insert(3);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;insert(3);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;insert(3);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;insert(3);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;delete();&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;insert(3);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;insert(3);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return 0;&nbsp;&nbsp;
&#125;&nbsp;&nbsp;
</textarea><br/><br/>来自：http://blog.csdn.net/huangkangying/article/details/44066729
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK] C语言-循环队列的简单实现]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>