<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IT元素 &#187; 队列</title>
	<atom:link href="http://www.ourys.com/tags/queue/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ourys.com</link>
	<description>Hector的编程笔记夹，如果喜欢，收藏一个</description>
	<lastBuildDate>Wed, 18 Jan 2012 22:07:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>队列（C++模版类实现）</title>
		<link>http://www.ourys.com/post/55.html</link>
		<comments>http://www.ourys.com/post/55.html#comments</comments>
		<pubDate>Wed, 24 Jun 2009 03:28:49 +0000</pubDate>
		<dc:creator>Hector</dc:creator>
				<category><![CDATA[数据结构]]></category>
		<category><![CDATA[队列]]></category>

		<guid isPermaLink="false">http://www.ourys.com/hector/ourys.com/?p=44</guid>
		<description><![CDATA[<br/>[CODE=cplusplus]<br/>/*//////////////////////////////////////////////////////////////////////////////<br/><br/>// 名    称 (Unit Name)  :    队列 Queue.h 头文件<br/><br/>// 作    者 (Author)     :    Hector(张伟)<br/><br/>// 邮    箱 (E-mai
]]></description>
			<content:encoded><![CDATA[<p>[CODE=cplusplus]<br/>/*//////////////////////////////////////////////////////////////////////////////<br/><br/>// 名    称 (Unit Name)  :    <span class='wp_keywordlink_affiliate'><a href="http://www.ourys.com/tags/queue" title="查看 队列 中的全部文章" target="_blank">队列</a></span> Queue.h 头文件<br/><br/>// 作    者 (Author)     :    Hector(张伟)<br/><br/>// 邮    箱 (E-mail)     :    ourys@qq.com<br/><br/>// 支    持 (Support)    :    http://www.ourys.com           <br/><br/>// 备    注 (Remarks)    :    <br/><br/>//////////////////////////////////////////////////////////////////////////////*/<br/><br/>#ifndef _QUEUE_H<br/><br/>#define _QUEUE_H<br/><br/>#define QUEUE_INIT_SIZE 100    //初始<span class='wp_keywordlink_affiliate'><a href="http://www.ourys.com/tags/queue" title="查看 队列 中的全部文章" target="_blank">队列</a></span>的最大长度<br/><br/>#define QUEUEINCREMENT 10      //每次新增的长度<br/><br/>template <class DataType><br/><br/>class Queue{<br/><br/>public:<br/><br/>Queue();                   //构造函数，创建一个新的<span class='wp_keywordlink_affiliate'><a href="http://www.ourys.com/tags/queue" title="查看 队列 中的全部文章" target="_blank">队列</a></span><br/><br/>bool EnQueue(DataType e);  //插入一个值为e的队尾元素<br/><br/>bool GetHead(DataType &#038;e); //取出队头元素<br/><br/>bool DeQueue(DataType &#038;e); //删除队头元素<br/><br/>bool QueueEmpty();         //判断是否非空<br/><br/>bool Clear();              //清空队列<br/><br/>~Queue();       //销毁队列<br/><br/>private:<br/><br/>DataType *front;<br/><br/>DataType *rear;<br/><br/>int queuesize;<br/><br/>};<br/><br/>/*&#8212;&#8212;&#8212;&#8212;  构造函数，创建一个新的队列  &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/><br/>template <class DataType><br/><br/>Queue<DataType>::Queue()<br/><br/>{<br/><br/>if(!(front=(DataType*)malloc(QUEUE_INIT_SIZE*sizeof(DataType)))) exit(1);<br/><br/>rear=front;<br/><br/>queuesize=QUEUE_INIT_SIZE;<br/><br/>}<br/><br/>/*&#8212;&#8212;&#8212;&#8212;  插入一个值为e的队尾元素  &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/><br/>template <class DataType><br/><br/>bool Queue<DataType>::EnQueue(DataType e)<br/><br/>{<br/><br/>if(rear-front>=queuesize){<br/><br/>if(!(front=(DataType*)realloc(front,(queuesize+QUEUEINCREMENT)*sizeof(DataType)))) exit(1);<br/><br/>rear=front+queuesize;<br/><br/>queuesize+=QUEUEINCREMENT;<br/><br/>}<br/><br/>*rear++=e;<br/><br/>return true;<br/><br/>}<br/><br/>/*&#8212;&#8212;&#8212;&#8212;  取出队头元素  &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/><br/>template <class DataType><br/><br/>bool Queue<DataType>::GetHead(DataType &#038;e)<br/><br/>{<br/><br/>if(rear==front) return false;<br/><br/>e=*front;<br/><br/>return true;<br/><br/>}<br/><br/>/*&#8212;&#8212;&#8212;&#8212;  删除队头元素  &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/><br/>template <class DataType><br/><br/>bool Queue<DataType>::DeQueue(DataType &#038;e)<br/><br/>{<br/><br/>if(rear==front) return false;<br/><br/>e=*front;<br/><br/>DataType* temp;<br/><br/>temp=front;<br/><br/>while(temp!=rear)     //为了删除后的空间继续利用，所有元素都向前移一位<br/><br/>{<br/><br/>*temp=*(temp+1);<br/><br/>temp++;<br/><br/>}<br/><br/>rear&#8211;;<br/><br/>return true;<br/><br/>}<br/><br/>/*&#8212;&#8212;&#8212;&#8212; 判断是否非空  &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/>template <class DataType><br/>bool Queue<DataType>::QueueEmpty()<br/>{<br/> return rear==front? 1:0;<br/>}<br/><br/>/*&#8212;&#8212;&#8212;&#8212; 清空队列  &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/>template <class DataType><br/>bool Queue<DataType>::Clear()<br/>{<br/> rear=front;<br/> return true;<br/>}<br/><br/>/*&#8212;&#8212;&#8212;&#8212; 销毁队列  &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/><br/>template <class DataType><br/><br/>Queue<DataType>::~Queue()<br/><br/>{<br/><br/>free(front);<br/><br/>} <br/><br/>#endif <br/><br/> <br/><br/>/*&#8212;&#8212;&#8212;&#8212;&#8212;-   基本测试文件   &#8212;&#8212;-   Author:Hector &#8212;&#8212;-*/<br/><br/>#include<iostream><br/>#include “Queue.h”<br/>using namespace std;<br/>int main()<br/>{<br/> Queue<int> my;<br/> int temp;<br/> for(int i=2;i<10;i++)<br/> {<br/>  my.EnQueue(i);<br/>  my.GetHead(temp);<br/>  cout<<temp<<endl;<br/> }<br/> for(int i=2;i<10;i++)<br/> {<br/>  my.DeQueue(temp);<br/>  cout<<temp<<endl;<br/> }<br/> my.DestroyQueue();<br/> return 0;<br/>}<br/>[/CODE]<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ourys.com/post/55.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>队列的基本操作（c实现）</title>
		<link>http://www.ourys.com/post/54.html</link>
		<comments>http://www.ourys.com/post/54.html#comments</comments>
		<pubDate>Tue, 23 Jun 2009 00:53:19 +0000</pubDate>
		<dc:creator>Hector</dc:creator>
				<category><![CDATA[数据结构]]></category>
		<category><![CDATA[队列]]></category>

		<guid isPermaLink="false">http://www.ourys.com/hector/ourys.com/?p=43</guid>
		<description><![CDATA[<br/>[CODE=cplusplus]<br/>/*//////////////////////////////////////////////////////////////////////////////<br/>// 名    称 (Unit Name)  :    队列 Queue.h 头文件<br/>// 作    者 (Author)     :    Hector(张伟)<br/>// 邮    箱 (E-mail)
]]></description>
			<content:encoded><![CDATA[<p>[CODE=cplusplus]<br/>/*//////////////////////////////////////////////////////////////////////////////<br/>// 名    称 (Unit Name)  :    <span class='wp_keywordlink_affiliate'><a href="http://www.ourys.com/tags/queue" title="查看 队列 中的全部文章" target="_blank">队列</a></span> Queue.h 头文件<br/>// 作    者 (Author)     :    Hector(张伟)<br/>// 邮    箱 (E-mail)     :    ourys@qq.com<br/>// 支    持 (Support)    :    http://www.ourys.com           <br/>// 备    注 (Remarks)    :    <br/>//////////////////////////////////////////////////////////////////////////////*/<br/>typedef int Datatype;<br/>typedef struct tagQNode{<br/>    Datatype data;<br/>    struct tagQNode* next;<br/>}*QNode;<br/>typedef struct {<br/>    QNode front;<br/>    QNode rear;<br/>}*LinkQueue;<br/>/*&#8212;&#8212;&#8212;&#8212;  构造一个空的<span class='wp_keywordlink_affiliate'><a href="http://www.ourys.com/tags/queue" title="查看 队列 中的全部文章" target="_blank">队列</a></span>  &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/>LinkQueue InitQueue()<br/>{<br/>    LinkQueue q;<br/>    q->front=(QNode)malloc(sizeof(struct tagQNode));<br/>    if(!q->front) exit(1);<br/>    q->rear=q->front;<br/>    q->front->next=NULL;<br/>    return q;<br/>}<br/>/*&#8212;&#8212;&#8212;&#8212;  销毁<span class='wp_keywordlink_affiliate'><a href="http://www.ourys.com/tags/queue" title="查看 队列 中的全部文章" target="_blank">队列</a></span>    &#8212;&#8212;&#8212;&#8212;&#8211;*/<br/>int DestroyQueue(LinkQueue q)<br/>{<br/>    while(q->front){<br/>        q->rear=q->front->next;<br/>        free(q->front);<br/>        q->front=q->rear;<br/>    }<br/>    return 1;<br/>}<br/>/*&#8212;&#8212;&#8212;-   插入一个为e的队尾元素     &#8212;&#8212;&#8212;&#8211;*/<br/>void EnQueue(LinkQueue q,Datatype e)<br/>{<br/>    QNode p=(QNode)malloc(sizeof(struct tagQNode));<br/>    p->data=e;<br/>    p->next=NULL;<br/>    q->rear->next=p;<br/>    q->rear=p;<br/>}<br/>    <br/>/*&#8212;&#8212;&#8212;-  删除一个队头元素，并返回   &#8212;&#8212;&#8212;-*/<br/>Datatype DeQueue(LinkQueue q)<br/>{<br/>    if(q->front==q->rear) return 0;<br/>    Datatype e=q->front->next->data;<br/>    QNode p=q->front->next;<br/>    q->front->next=p->next;<br/>    if(q->rear==p) q->rear=q->front;<br/>    free(p);<br/>    return e;<br/>}<br/><br/>/*&#8212;&#8212;&#8212;&#8212;&#8212;-   基本测试文件   &#8212;&#8212;-   Author:Hector &#8212;&#8212;-*/<br/>#include <stdio.h><br/>#include <stdlib.h><br/>#include “Queue.h”<br/>int main(void)<br/>{<br/>    LinkQueue queue=InitQueue();<br/>    EnQueue(queue,5);<br/>    return 0;<br/>}<br/>[/CODE]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ourys.com/post/54.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

