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

做一个简单网站多少钱wordpress页面显示返回json

做一个简单网站多少钱,wordpress页面显示返回json,合肥做网站好的公司,手机网站建设视频教程_队列的接口实现#xff08;附图解和源码#xff09; 文章目录队列的接口实现#xff08;附图解和源码#xff09;前言一、定义结构体二、接口实现#xff08;附图解源码#xff09;1.初始化队列2.销毁队列3.队尾入队列4.判断队列是否为空5.队头出队列6.获取队列头部元素7…队列的接口实现附图解和源码 文章目录队列的接口实现附图解和源码前言一、定义结构体二、接口实现附图解源码1.初始化队列2.销毁队列3.队尾入队列4.判断队列是否为空5.队头出队列6.获取队列头部元素7.获取队列尾部元素8.获取队列中有效元素个数三、源代码展示1.test.c测试主函数2.Queue.h接口函数的声明3.Queue.c接口函数的实现总结前言 本文主要介绍对列中增删查改等接口实现结尾附总源码 一、定义结构体 在这里我们用链表的结构实现队列效率比数组高 这里和单链表不同的是需要定义两个结构体一个表示链式结构队列另一个是队列的结构。 代码如下示例 typedef int QDataType; typedef struct QueueNode {struct QueueNode* next;QDataType data; }QNode; typedef struct Queue {QNode* head;QNode* tail;int size; }Queue;二、接口实现附图解源码 这里一共8个接口我会一 一 实现源码图解 1.初始化队列 初始化队列和单链表初始化时一致详细的可以参考单链表初始化 代码如下示例 void QueueInit(Queue* pq) {assert(pq);pq-head pq-tail NULL;pq-size 0; }2.销毁队列 最后不要忘了把pq-head和pq-tail置为NULL 代码如下示例 void QueueDestroy(Queue* pq) {assert(pq);QNode* cur pq-head;while (cur){QNode* del cur;cur cur-next;free(del);}pq-head pq-tail NULL; }3.队尾入队列 先用 malloc 开辟一个 newnode 空间 代码如下示例 void QueuePush(Queue* pq, QDataType x) {assert(pq);QNode* newnode (QNode*)malloc(sizeof(QNode));if (newnode NULL){perror(malloc fail);exit(-1);}else{newnode-data x;newnode-next NULL;}if (pq-tail NULL){pq-head pq-tail newnode;}else{pq-tail-next newnode;pq-tail newnode;}pq-size; }既然要不断判断链表是否为空我们应该写一个 判断队列是否为空的函数。 4.判断队列是否为空 如果为空返回非零结果如果非空返回0 代码如下示例 bool QueueEmpty(Queue* pq) {assert(pq);return pq-head NULL pq-tail NULL; }5.队头出队列 注意删除头对列时要注意队列可以为空所以用assert进行断言 这里也分两种情况1.队列只有一个结点2.队列有两个以上的结点。 6.获取队列头部元素 直接返回 pq-head-data 即可。 代码如下示例 QDataType QueueFront(Queue* pq) {assert(pq);assert(!QueueEmpty(pq));return pq-head-data; }7.获取队列尾部元素 直接返回 pq-tail-data 即可。 代码如下示例 QDataType QueueBack(Queue* pq) {assert(pq);assert(!QueueEmpty(pq));return pq-tail-data; }8.获取队列中有效元素个数 直接返回 pq-size 即可 代码如下示例 int QueueSize(Queue* pq) {assert(pq);return pq-size; }如果我们没有在结构体中定义 size 应该怎么做? 代码如下示例 int QueueSize(Queue* pq) {assert(pq);QNode* cur pq-head;int n 0;while (cur){n;cur cur-next;}return n; }三、源代码展示 1.test.c测试主函数 代码如下示例 //#include stdio.h // //int f(int n) //{ // return n 1 ? 1 : f(n - 1) n; //} // //int main() //{ // printf(%d\n, f(10000)); // // return 0; //} #include stdio.h #include Stack.h #include Queue.h // 解耦 -- 低耦合 高内聚 // 数据结构建议不要直接访问结构数据一定要通过函数接口访问 void TestStack() {ST st;StackInit(st);StackPush(st, 1);StackPush(st, 2);StackPush(st, 3);printf(%d , StackTop(st));StackPop(st);printf(%d , StackTop(st));StackPop(st);StackPush(st, 4);StackPush(st, 5);while (!StackEmpty(st)){printf(%d , StackTop(st));StackPop(st);}printf(\n); } void TestQueue() {Queue q;QueueInit(q);QueuePush(q, 1);QueuePush(q, 2);QueuePush(q, 3);printf(%d , QueueFront(q));QueuePop(q);printf(%d , QueueFront(q));QueuePop(q);QueuePush(q, 4);QueuePush(q, 4);QueuePush(q, 4);while (!QueueEmpty(q)){printf(%d , QueueFront(q));QueuePop(q);}printf(\n);QueueDestroy(q); } int main() {//TestStack();TestQueue();return 0; }2.Queue.h接口函数的声明 代码如下示例 #pragma once #include stdio.h #include stdlib.h #include assert.h #include stdbool.h typedef int QDataType; typedef struct QueueNode {struct QueueNode* next;QDataType data; }QNode; typedef struct Queue {QNode* head;QNode* tail;int size; }Queue;void QueueInit(Queue* pq);//初始化队列 void QueueDestroy(Queue* pq);//销毁队列 void QueuePush(Queue* pq, QDataType x);//队尾入队列 void QueuePop(Queue* pq);//队头入队列 QDataType QueueFront(Queue* pq);//获取队列头部元素 QDataType QueueBack(Queue* pq);//获取队列尾部元素 bool QueueEmpty(Queue* pq);//判断队列是否为空 int QueueSize(Queue* pq);//获取队列中有效元素个数3.Queue.c接口函数的实现 代码如下示例 #include Queue.h void QueueInit(Queue* pq) {assert(pq);pq-head pq-tail NULL;pq-size 0; } void QueueDestroy(Queue* pq) {assert(pq);QNode* cur pq-head;while (cur){QNode* del cur;cur cur-next;free(del);}pq-head pq-tail NULL; } void QueuePush(Queue* pq, QDataType x) {assert(pq);QNode* newnode (QNode*)malloc(sizeof(QNode));if (newnode NULL){perror(malloc fail);exit(-1);}else{newnode-data x;newnode-next NULL;}if (pq-tail NULL){pq-head pq-tail newnode;}else{pq-tail-next newnode;pq-tail newnode;}pq-size; } void QueuePop(Queue* pq) {assert(pq);assert(!QueueEmpty(pq));if (pq-head-next NULL){free(pq-head);pq-head pq-tail NULL;}else{QNode* del pq-head;pq-head pq-head-next;free(del);del NULL;}pq-size--; } QDataType QueueFront(Queue* pq) {assert(pq);assert(!QueueEmpty(pq));return pq-head-data; } QDataType QueueBack(Queue* pq) {assert(pq);assert(!QueueEmpty(pq));return pq-tail-data; } bool QueueEmpty(Queue* pq) {assert(pq);return pq-head NULL pq-tail NULL; } int QueueSize(Queue* pq) {assert(pq);/*QNode* cur pq-head;int n 0;while (cur){n;cur cur-next;}return n;*/return pq-size; }总结 以上就是今天要讲的内容本文介绍了队列8种接口的模拟实现的图解源代码 如果我的博客对你有所帮助记得三连支持一下感谢大家的支持
http://www.yingshimen.cn/news/56649/

相关文章:

  • 潇朋友免费班级网站建设系统优化seo设置
  • 图片类网站建设新网站百度有审核期
  • 怎么做刷赞网站将wordpress做成淘宝客
  • 做网站页面多少钱微信小游戏开发软件
  • 单页面网站设计网站欣赏太原新站优化
  • 山东兴华建设集团有限公司网站拼音c mvc网站开发实例教程
  • 上海网站建设咨询站霸网络什么专业可以做网站编辑
  • 网站tdk建设php英文网站源码
  • 建设部网站监理变更电脑培训班一般要学多久
  • 政务信息网站建设制度商城网站素材
  • 建网站不花钱免费谷歌海外广告投放
  • 上海市区网站设计制作公司山西建筑劳务网站
  • 手机网站开发免费视频教程wordpress搜索功能
  • 北师大网页制作与网站建设kali搭建wordpress
  • 网站绝对布局邵阳seo快速排名
  • 网站维护界面设计ppt背景图片
  • 网站seo优化培训傻瓜式做网站哪个软件好
  • 湖州网站建设方案网站添加支付宝
  • 做ui的网站泰州网页设计需要多少钱
  • 软文发布网站备案号被取消 没有重新备案网站会被关闭吗
  • 做网站需要提供的资料网页素材免费下载
  • 企业网站推广的模式用dw制作个人网页
  • 贵州省住房城乡建设厅网站wordpress怎么调用默认的分页代码
  • 北京市朝阳区网站开发公司申请网站建设费
  • 即墨区建设局网站wordpress 模拟post
  • 网站建设 优势手机网站建设哪家强
  • 嘉兴手机建站模板网站备案是什么
  • 好网站的特点旅游类网站模板免费下载
  • gta5此网站正在建设合肥企业网站营销电话
  • 网站开发的技术栈搜索引擎关键词竞价排名