循环队列基本操作-华为OJ.docx

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
循环队列基本操作-华为OJ

/****************************************************************************** Copyright (C), 2001-2011, Huawei Tech. Co., Ltd. ****************************************************************************** File Name : Version : Author : Created : 2012/03/12 Last Modified : Description : Function List : History :1.Date : 2012/03/12 Author : Modification: Created file******************************************************************************/#includestdlib.h#defineMAXSIZE 50structstrqueue {int queue[MAXSIZE];int head; /* 队头 */int tail; /* 队尾 */intnum; /* 队元素个数 */};boolinitqueue(structstrqueue *s){if (!s)return 0;for (inti = 0; i MAXSIZE; i++) {s-queue[i] = 0;}s-head = -1;s-tail = -1;s-num = 0;return 1;}boolenqueue(structstrqueue *s, intx) /* 进队列,返回0表示失败,返回1表示成功 */{if (!s)return 0;if (s-num == MAXSIZE)return 0;if (s-head == -1 || s-tail == -1) {s-head = 0;s-tail = 0;s-queue[s-tail] = x; /*赋值*/s-num = 1;return 1;}s-tail = (s-tail + 1) % MAXSIZE;s-queue[s-tail] = x;s-num++;return 1;}booldequeue(structstrqueue *s, int *x) /* 出队列,返回0表示失败,返回1表示成功 */{if (!s || !x)return 0;if (s-num == 0)return 0;*x = s-queue[s-head]; /*赋值*/s-queue[s-head] = 0;s-head = (s-head + 1) % MAXSIZE;/*从对头出队列*/s-num--;if (s-num == 0) {s-head = -1;s-tail = -1;}return 1;}intgethead(structstrqueue *s) /* 获得队列头数值 */{if (!s)return -1;if (s-num == 0)return -1;int head = 0;head = s-queue[s-head];return head;}intgettail(structstrqueue *s) /* 获得队列尾数值 */{if (!s)return 0;int tail = 0;if (s-num == 0)return -1;tail = s-queue[s-tail];return tail;}intgetqueuelenth(structstrqueue *s) /* 获得队列长度 */{if (!s)return 0;intlenth = 0;lenth = s-num;returnlenth;}bool search(structstrqueue *s, intx) /* 在队列中查找x是否存在,如果存在返回1,否则返回0 */{if (!s)return 0;intheadTemp = s-head;inttailTemp = s-tail;if (s-num == MAXSIZE) {for (inti = 0; i MAXSIZE; i++) {if (x == s-queue[i])return 1;}}else {while (headTemp != tailTemp) {if (x == s-queue[headTemp])return 1;headTemp = (

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档