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

学做ppt的网站两性做受技巧视频网站

学做ppt的网站,两性做受技巧视频网站,做网站简介,怎么买做淘宝优惠券网站数据结构——队列 一、队列的概念二、队列的实现方式三、队列所需要的接口四、接口的详细实现4.1初始化4.2销毁4.3入队4.5出队4.6获取队头元素4.7获取队尾元素4.8获取队列元素个数4.9判空 五、完整代码5.1Queue.h5.2Queue.c5.3test.c 一、队列的概念 队列#xff1a;只允许在… 数据结构——队列 一、队列的概念二、队列的实现方式三、队列所需要的接口四、接口的详细实现4.1初始化4.2销毁4.3入队4.5出队4.6获取队头元素4.7获取队尾元素4.8获取队列元素个数4.9判空 五、完整代码5.1Queue.h5.2Queue.c5.3test.c 一、队列的概念 队列只允许在一端进行插入数据操作在另一端进行删除数据操作的特殊线性表 队列具有先进先出FIFO(First In First Out) 入队列进行插入操作的一端称为队尾 。 出队列进行删除操作的一端称为队头。二、队列的实现方式 队列可以用数组和链表的结构实现使用链表的结构实现更优一些因为如果使用数组的结构出队列在数组头上出数据效率会比较低。 三、队列所需要的接口 //初始化 void QueueInit(Queue* pq);//销毁 void QueueDestory(Queue* pq);//入队 void QueuePush(Queue* pq, Queuedatatype x);//出队 void QueuePop(Queue* pq);//获取队头元素 Queuedatatype QueueFront(Queue* pq);//获取队尾元素 Queuedatatype QueueBack(Queue* pq);//获取队列元素个数 int Queuesize(Queue* pq);//判空 bool QueueEmpty(Queue* pq);四、接口的详细实现 4.1初始化 初始化我们需要将pq-phead和pq-ptail都置为NULL并且将pq-size置为0 oid QueueInit(Queue* pq) {assert(pq);pq-phead NULL;pq-ptail NULL;pq-size 0; }4.2销毁 销毁首先定义一个cur指针保存头节点phead的地址接下来利用cur!NULL使得循环往下走在循环内定义一个next的指针来更新地址并且用free来释放内存出循环后将pq-phead,pq-ptail都置为NULL,并且将pq-size置为0。 void QueueDestory(Queue* pq) {assert(pq);Queuenode* cur pq-phead;while (cur){Queue* next cur-next;free(cur);cur next;}pq-phead pq-ptail NULL;pq-size 0; }4.3入队 入队入队有两种情况。第一种队内无其他元素第二种队内有其他元素。 ①、队内无其他元素直接让pq-phead pq-ptail newnode; ②、队内有其它元素如果队列不为NULL,我们需要让pq-ptail-next指向newnode,并且最后再让pq-ptail指向newnode. oid QueuePush(Queue* pq, Queuedatatype x) {assert(pq);Queuenode* newnode (Queuenode*)malloc(sizeof(Queuenode));if (newnode NULL){perror(malloc fail);return;}newnode-data x;newnode-next NULL;//队内无其它元素if (pq-phead NULL){assert(pq-ptail NULL);pq-phead pq-ptail newnode;}else{//链接pq-ptail-next newnode;pq-ptail newnode;}pq-size; } 4.5出队 出队出队列大体上分为两种情况有节点和无节点。 ①、如果队列中没有节点就不能进行出队操作我们这时可以用assert(!QueueEmpty(pq)); 来进行判断。 ②、队列中有节点时又可以分为一个节点和多个节点之分如果队列中只有一个节点时我们直接用free 置空如果队列中有多个节点时首先、创建一个next用来保存phead的下一个节点的地址我们free(phead)再让phead等于我们的next。 // 出队 void QueuePop(Queue * pq) {assert(pq);assert(!QueueEmpty(pq));//一个节点if (pq-phead-next NULL){free(pq-phead);pq-phead pq-ptailNULL;}//多个节点else{//头删Queuenode* next pq-phead-next;free(pq-phead);pq-phead next;}pq-size--; }4.6获取队头元素 //获取队头元素 Queuedatatype QueueFront(Queue* pq) {assert(pq);return pq-phead-data; }4.7获取队尾元素 //获取队尾元素 Queuedatatype QueueBack(Queue* pq) {assert(pq);return pq-ptail-data; }4.8获取队列元素个数 //获取队列元素个数 int Queuesize(Queue* pq) {assert(pq);return pq-size; }4.9判空 如果pq-size0时便证明队列为NULL。 //判空 bool QueueEmpty(Queue* pq) {assert(pq);return pq-size 0; }五、完整代码 5.1Queue.h #pragma once #includestdio.h #includeassert.h #includestdlib.h #includestdbool.htypedef int Queuedatatype; //定义队列结构 typedef struct Queuenode {struct Queuenode* next;Queuedatatype data; }Queuenode;typedef struct Queue {Queuenode* phead;Queuenode* ptail;int size; }Queue;//初始化 void QueueInit(Queue* pq);//销毁 void QueueDestory(Queue* pq);//入队 void QueuePush(Queue* pq, Queuedatatype x);//出队 void QueuePop(Queue* pq);//获取队头元素 Queuedatatype QueueFront(Queue* pq);//获取队尾元素 Queuedatatype QueueBack(Queue* pq);//获取队列元素个数 int Queuesize(Queue* pq);//判空 bool QueueEmpty(Queue* pq);5.2Queue.c #define _CRT_SECURE_NO_WARNINGS 1 #includeQueue.h //初始化 void QueueInit(Queue* pq) {assert(pq);pq-phead NULL;pq-ptail NULL;pq-size 0; }//销毁 void QueueDestory(Queue* pq) {assert(pq);Queuenode* cur pq-phead;while (cur){Queue* next cur-next;free(cur);cur next;}pq-phead pq-ptail NULL;pq-size 0; }//入队 void QueuePush(Queue* pq, Queuedatatype x) {assert(pq);Queuenode* newnode (Queuenode*)malloc(sizeof(Queuenode));if (newnode NULL){perror(malloc fail);return;}newnode-data x;newnode-next NULL;if (pq-phead NULL){assert(pq-ptail NULL);pq-phead pq-ptail newnode;}//链接pq-ptail-next newnode;pq-ptail newnode;pq-size; }// 出队 void QueuePop(Queue * pq) {assert(pq);assert(!QueueEmpty(pq));//一个节点if (pq-phead-next NULL){free(pq-phead);pq-phead pq-ptailNULL;}//多个节点else{//头删Queuenode* next pq-phead-next;free(pq-phead);pq-phead next;}pq-size--; }//获取队头元素 Queuedatatype QueueFront(Queue* pq) {assert(pq);return pq-phead-data; }//获取队尾元素 Queuedatatype QueueBack(Queue* pq) {assert(pq);return pq-ptail-data; }//获取队列元素个数 int Queuesize(Queue* pq) {assert(pq);return pq-size; }//判空 bool QueueEmpty(Queue* pq) {assert(pq);return pq-size 0; }5.3test.c #define _CRT_SECURE_NO_WARNINGS 1 #includeQueue.h void test1() {Queue q;QueueInit(q);QueuePush(q, 1);QueuePush(q, 2);QueuePush(q, 3);QueuePush(q, 4);printf(Size:%d\n, Queuesize(q));while (!QueueEmpty(q)){printf(%d , QueueFront(q));QueuePop(q);}} int main() {test1();return 0; }
http://www.hkea.cn/news/14371898/

相关文章:

  • 网站建设与运营的收入来源多店铺商城系统开发
  • 建行国际互联网网站受欢迎的网站开发
  • wordpress建2个网站吗网络营销第三版课本
  • 创世网站网络建设网站建设的成本有哪些内容
  • 家具公司网站页面设计模板wordpress seo
  • 网站备案取消流程谁做视频网站
  • 公司建网站会计分录开源网站推广
  • 如何更换网站服务商山东网站建设优化技术
  • h5网站开发工具淮北建设银行官方网站
  • 常州自助建站seo中国建设机械网网址
  • 淮北 网站建设 有限公司cc彩球网站总代理怎么做
  • 电子政务门户网站建设汇报做一个网站怎么做的
  • 建建建设网站滁州58同城网站怎么做
  • 地图网站开发网页设计与制作项目教程素材
  • 企业网站主题网站制作应该选什么
  • 国外推广网站少儿编程app
  • wordpress网站云备份十大创意广告策划
  • 网站建设外包需要注意哪些科技网站欣赏
  • 深圳住房与建设部网站广东阳江房产网
  • 政务信息网站建设工作方案什么是网络营销产生的的技术原因
  • 网站建设报销属于什么会计科目代理赚钱
  • 做网站的人月平地起建筑人才网
  • 南通做网站优化哪家好做代收的网站有哪些
  • 平度好的建设网站有产品怎么找销售渠道
  • 网站开发招标做食品企业网站的费用
  • 先做网站再付款 怎么回答陕西西安网站建设
  • 深圳市建设局官方网站能力建设和继续教育中心网站
  • 北京网站建设+知乎网站怎样做排名
  • 举例描述该如何布局网站关键词wordpress主题logo
  • 网站地址栏小图标石家庄网站制作报价