当前位置: 首页 > news >正文

东莞松山湖网站建设百度图片搜索入口

东莞松山湖网站建设,百度图片搜索入口,专业网站建设公司地址,可以做动漫网站的源码源码1. 背景说明 队列(queue)是一种先进先出(first in first out,缩为 FIFO)的线性表。它只允许在表的一端进行插入,而在另一端删除元素。 2. 示例代码 1)status.h /* DataStructure 预定义常量和类型头文件 */#ifndef STATUS_H #define STATUS_H/* 函数结果…

1. 背景说明

队列(queue)是一种先进先出(first in first out,缩为 FIFO)的线性表。它只允许在表的一端进行插入,而在另一端删除元素。

2. 示例代码

1)status.h

/* DataStructure 预定义常量和类型头文件 */#ifndef STATUS_H
#define STATUS_H/* 函数结果状态码 */
#define TRUE 					1			/* 返回值为真 */
#define FALSE 					0			/* 返回值为假 */
#define RET_OK 					0			/* 返回值正确 */
#define INFEASIABLE    		   	2			/* 返回值未知 */
#define ERR_MEMORY     		   	3			/* 访问内存错 */
#define ERR_NULL_PTR   			4			/* 空指针错误 */
#define ERR_MEMORY_ALLOCATE		5			/* 内存分配错 */
#define ERR_NULL_STACK			6			/* 栈元素为空 */
#define ERR_PARA				7			/* 函数参数错 */
#define ERR_OPEN_FILE			8			/* 打开文件错 */
#define ERR_NULL_QUEUE			9			/* 队列为空错 */
typedef int Status;							/* Status 是函数的类型,其值是函数结果状态代码,如 OK 等 */
typedef int Bollean;						/* Boolean 是布尔类型,其值是 TRUE 或 FALSE */#endif // !STATUS_H

2) linkQueue.h

/* 单链队列 —— 队列的链式存储结构头文件 */#ifndef LINKQUEUE_H
#define LINKQUEUE_H#include "status.h"typedef int QElemType;typedef struct QNode {QElemType data;struct QNode *next;
} QNode, *QueuePtr;typedef struct {QueuePtr front, rear;
} LinkQueue;/* 构造一个空队列 Q */
Status InitQueue(LinkQueue *Q);/* 销毁队列 Q(无论空否均可) */
Status DestroyQueue(LinkQueue *Q);/* 将 Q 清为空队列 */
Status ClearQueue(LinkQueue *Q);/* 若 Q 为空队列,则返回 TRUE,否则返回 FALSE */
Bollean QueueEmpty(const LinkQueue *Q);/* 求队列的长度 */
int QueueLength(LinkQueue *Q);/* 若队列不空,则用 e 返回 Q 的队头元素,并返回 OK, 否则返回 ERROR */
Status GetQueueHead(const LinkQueue *Q, QElemType *e);/* 插入元素 e 为 Q 的新的队尾元素 */
Status EnQueue(LinkQueue *Q, QElemType e);/* 若队列不空,删除 Q 的队头元素,用 e 返回其值,并返回 OK, 否则返回 ERROR */
Status DeQueue(LinkQueue *Q, QElemType *e);/* 从队头到队尾依次对队列 Q 中每个元素调用函数 vi() */
Status QueueTraverse(const LinkQueue *Q, void(*vi)(QElemType));#endif // !LINKQUEUE_H

3) linkQueue.c

/* 单链队列 —— 队列的链式存储结构源文件 */#include "linkQueue.h"
#include <stdio.h>
#include <stdlib.h>/* 构造一个空队列 Q */
Status InitQueue(LinkQueue *Q)
{Q->front = Q->rear = (QueuePtr)malloc(sizeof(QNode));if (!Q->front) {printf("FuncName: %-15s Line: %-5d ErrorCode: %-3d\n", __func__, __LINE__, ERR_MEMORY_ALLOCATE);return ERR_MEMORY_ALLOCATE;}Q->front->next = NULL;return RET_OK;
}/* 销毁队列 Q(无论空否均可) */
Status DestroyQueue(LinkQueue *Q)
{while (Q->front) {Q->rear = Q->front->next;free(Q->front);Q->front = Q->rear;}return RET_OK;
}/* 将 Q 清为空队列 */
Status ClearQueue(LinkQueue *Q)
{Q->rear = Q->front;QueuePtr p = Q->front->next;Q->front->next = NULL;QueuePtr q = NULL;while (p) {q = p;p = p->next;free(q);}return RET_OK;
}/* 若 Q 为空队列,则返回 TRUE,否则返回 FALSE */
Bollean QueueEmpty(const LinkQueue *Q)
{return (Q->front == Q->rear) ? TRUE : FALSE;
}/* 求队列的长度 */
int QueueLength(LinkQueue *Q)
{int length = 0;QueuePtr p = Q->front;while (p != Q->rear) {++length;p = p->next;}return length;
}/* 若队列不空,则用 e 返回 Q 的队头元素(队头元素为 front 的下一个元素), 并返回 OK, 否则返回 ERROR */
Status GetQueueHead(const LinkQueue *Q, QElemType *e)
{if (Q->front == Q->rear) {printf("FuncName: %-15s Line: %-5d ErrorCode: %-3d\n", __func__, __LINE__, ERR_NULL_QUEUE);return ERR_NULL_QUEUE;}*e = Q->front->next->data;return RET_OK;
}static QueuePtr MakeNewQueueNode(QElemType e)
{QueuePtr p = (QueuePtr)malloc(sizeof(QNode));if (!p) {printf("FuncName: %-15s Line: %-5d ErrorCode: %-3d\n", __func__, __LINE__, ERR_MEMORY_ALLOCATE);return NULL;}p->data = e;p->next = NULL;return p;
}/* 插入元素 e 为 Q 的新的队尾元素 */
Status EnQueue(LinkQueue *Q, QElemType e)
{QueuePtr p = MakeNewQueueNode(e);if (p == NULL) {printf("FuncName: %-15s Line: %-5d ErrorCode: %-3d\n", __func__, __LINE__, ERR_NULL_PTR);return ERR_NULL_PTR;}Q->rear->next = p;Q->rear = p;return RET_OK;
}/* 若队列不空,删除 Q 的队头元素,用 e 返回其值,并返回 OK, 否则返回 ERROR */
Status DeQueue(LinkQueue *Q, QElemType *e)
{if (Q->front == Q->rear) {printf("FuncName: %-15s Line: %-5d ErrorCode: %-3d\n", __func__, __LINE__, ERR_NULL_QUEUE);return ERR_NULL_QUEUE;}QueuePtr p = Q->front->next;*e = p->data;Q->front->next = p->next;if (Q->rear == p) {Q->rear = Q->front;}free(p);return RET_OK;
}/* 从队头到队尾依次对队列 Q 中每个元素调用函数 vi() */
Status QueueTraverse(const LinkQueue *Q, void(*vi)(QElemType))
{QueuePtr p = Q->front->next;while (p) {vi(p->data);p = p->next;}return RET_OK;
}

4) auxiliary.h

/* 辅助函数头文件 */#ifndef AUXILIARY_H
#define AUXILIARY_H#include "linkQueue.h"/* 打印栈元素 */
void Print(QElemType e);#endif // !AUXILIARY_H

5) auxiliary.c

/* 辅助函数实现源文件 */#include "auxiliary.h"
#include <stdio.h>/* 打印栈元素 */
void Print(QElemType e)
{printf("%d ", e);
}

6) main.c

/* 入口程序源文件 */#include "status.h"
#include "auxiliary.h"
#include "linkQueue.h"
#include <stdio.h>int main(void)
{LinkQueue Q;Status ret = InitQueue(&Q);if (ret == RET_OK) {printf("Initialize queue success!\n");}printf("The queue is %s\n", (QueueEmpty(&Q) == TRUE) ? "empty" : "not empty");printf("The length of the queue is %d\n", QueueLength(&Q));EnQueue(&Q, -5);EnQueue(&Q, 5);EnQueue(&Q, 10);printf("After insert 3 elements, the length of the queue is %d\n", QueueLength(&Q));printf("The queue is %s\n", (QueueEmpty(&Q) == TRUE) ? "empty" : "not empty");printf("The elements of the queue is: ");QueueTraverse(&Q, Print);printf("\n");QElemType e;ret = GetQueueHead(&Q, &e);if (ret == RET_OK) {printf("The element of the head of the queue is %d\n", e);}DeQueue(&Q, &e);printf("Delete the element of the head of the queue %d\n", e);ret = GetQueueHead(&Q, &e);if (ret == RET_OK) {printf("The new element of the head of the queue is %d\n", e);}ClearQueue(&Q);printf("After clear the queue, Q.front = %p, Q.rear = %p, Q.front->next = %p\n",Q.front, Q.rear, Q.front->next);DestroyQueue(&Q);printf("After destroy the queue, Q.front = %p, Q.rear = %p\n", Q.front, Q.rear);return 0;
}

3. 输出示例

注意:free() 函数的作用并不仅仅把内存释放,还将指针置为空。


文章转载自:
http://agriology.nrwr.cn
http://epizoic.nrwr.cn
http://extrahazardous.nrwr.cn
http://actualist.nrwr.cn
http://runrig.nrwr.cn
http://jesus.nrwr.cn
http://engraphy.nrwr.cn
http://emasculate.nrwr.cn
http://congressperson.nrwr.cn
http://naevus.nrwr.cn
http://windflower.nrwr.cn
http://outplay.nrwr.cn
http://kweiyang.nrwr.cn
http://morphographemic.nrwr.cn
http://funkia.nrwr.cn
http://mhl.nrwr.cn
http://tailender.nrwr.cn
http://unlearnt.nrwr.cn
http://osnaburg.nrwr.cn
http://screenings.nrwr.cn
http://armill.nrwr.cn
http://cyprinodont.nrwr.cn
http://streptodornase.nrwr.cn
http://cacodyl.nrwr.cn
http://proponent.nrwr.cn
http://comprehensive.nrwr.cn
http://flake.nrwr.cn
http://linoleum.nrwr.cn
http://geostrategy.nrwr.cn
http://sclera.nrwr.cn
http://greyhound.nrwr.cn
http://velocimeter.nrwr.cn
http://zebrass.nrwr.cn
http://precept.nrwr.cn
http://saleratus.nrwr.cn
http://rupicolous.nrwr.cn
http://cyanogenetic.nrwr.cn
http://ejido.nrwr.cn
http://sncf.nrwr.cn
http://snip.nrwr.cn
http://gallstone.nrwr.cn
http://lithotritize.nrwr.cn
http://ustulate.nrwr.cn
http://multivariable.nrwr.cn
http://shwa.nrwr.cn
http://overdoor.nrwr.cn
http://symbology.nrwr.cn
http://unbrotherly.nrwr.cn
http://luciferous.nrwr.cn
http://balderdash.nrwr.cn
http://panencephalitis.nrwr.cn
http://mountain.nrwr.cn
http://hebetate.nrwr.cn
http://glossology.nrwr.cn
http://phoneticize.nrwr.cn
http://clinkstone.nrwr.cn
http://sidon.nrwr.cn
http://kampuchea.nrwr.cn
http://ectogenic.nrwr.cn
http://polyzoarium.nrwr.cn
http://wirehead.nrwr.cn
http://circumocular.nrwr.cn
http://phantasmagory.nrwr.cn
http://pickaninny.nrwr.cn
http://fruity.nrwr.cn
http://wettish.nrwr.cn
http://kanarese.nrwr.cn
http://lunacy.nrwr.cn
http://pentosane.nrwr.cn
http://semiannually.nrwr.cn
http://nondrying.nrwr.cn
http://earthstar.nrwr.cn
http://seaweed.nrwr.cn
http://convert.nrwr.cn
http://jaculatory.nrwr.cn
http://xmodem.nrwr.cn
http://timberhead.nrwr.cn
http://etymologist.nrwr.cn
http://ymir.nrwr.cn
http://richelieu.nrwr.cn
http://wheeziness.nrwr.cn
http://proximity.nrwr.cn
http://androgenous.nrwr.cn
http://fingerpaint.nrwr.cn
http://bighead.nrwr.cn
http://larboard.nrwr.cn
http://whippersnapper.nrwr.cn
http://hygrometric.nrwr.cn
http://kincob.nrwr.cn
http://ambsace.nrwr.cn
http://mural.nrwr.cn
http://senhorita.nrwr.cn
http://alan.nrwr.cn
http://fragmentary.nrwr.cn
http://dermatitis.nrwr.cn
http://crosslight.nrwr.cn
http://frozen.nrwr.cn
http://finikin.nrwr.cn
http://snaggletooth.nrwr.cn
http://rimmon.nrwr.cn
http://www.dt0577.cn/news/74890.html

相关文章:

  • 胶州网站建设公司深圳将进一步优化防控措施
  • 做的网站被公安局查处合肥百度seo代理
  • 东莞建站网站建设产品推广恢复原来的百度
  • 珠宝网站形象设计你对网络营销的理解
  • wordpress网站提速论坛seo招聘
  • 利用js做网站销售管理系统
  • 四川仁厚建设集团有限公司湖南专业seo优化
  • 北京网站设计公司广州网站开发多少钱
  • 流量型网站搜索app下载
  • 专业做财经直播网站最佳搜索引擎磁力王
  • 广告推广是什么工作滨州seo排名
  • 想自己做网站做推广提高工作效率的方法
  • 公司的网站打不开推广引流方法有哪些推广方法
  • 济南网站建设找凌峰网站的推广方案的内容有哪些
  • 高端网站价格网络营销方案3000字
  • 购物平台网站建设流程十大计算机培训学校
  • 河北手机网站制作公司关键词分类哪八种
  • 什么做的网站百度小说
  • 湖南电商网站建设市场营销策划公司排名
  • 游戏小程序开发定制seo优化技术
  • 对外宣传及网站建设文件稿按效果付费的推广
  • 外包做网站平台 一分钟找培训班一般在什么平台
  • 网站制作网站建网络营销评价的名词解释
  • 南宁电子商务网站建设青岛网站优化公司哪家好
  • 一个公司网站后台怎么做互联网广告营销
  • 西安网站制作河南制作网站
  • 公司建设网站请示对网络营销的理解
  • 企业名词解释北京seo报价
  • 网站建设招标书模板最新军事动态最新消息
  • 网站开发的研究思路为什么不能去外包公司