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

建设网站时seo标题wordpress 运费模板下载

建设网站时seo标题,wordpress 运费模板下载,广东东莞1例新冠状,上海市人力资源网官网问题描述#xff1a; 请你仅用两个队列实现一个后入先出#xff08;LIFO#xff09;的栈#xff0c;并支持普通队列的全部四种操作#xff08;push、top、pop和empty#xff09;。 实现MyStack类#xff1a; void push(int x) 将元素x压入栈顶。int pop()移除并返回栈顶…问题描述 请你仅用两个队列实现一个后入先出LIFO的栈并支持普通队列的全部四种操作push、top、pop和empty。 实现MyStack类 void push(int x) 将元素x压入栈顶。int pop()移除并返回栈顶元素。int top()返回栈顶元素。boolean empty()如果栈是空的返回true否则返回false。 解题思路  1. 入数据往不为空的队列入 2. 出数据把不为空的队列数据导入为空直至只剩最后一个 解决本题之前要先将队列的各类接口函数准备好队列的接口函数我上一篇中提到了喔 #includestdio.h #includestdbool.h #includeassert.h #includestdlib.h typedef int QDataType; typedef struct QueueNode {struct QueueNode* next;QDataType data; }QNode;//删除数据和插入数据需要记录头结点和尾结点 typedef struct Queue {QNode* head;QNode* tail; }Queue; void QueueInit(Queue* pq); void QueueDestory(Queue* pq); //队尾入 void QueuePush(Queue* pq, QDataType x); //队头出 void QueuePop(Queue* pq); //取队头的数据 QDataType QueueFront(Queue* pq); //取队尾的数据 QDataType QueueBack(Queue* pq); //取数据的个数 int QueueSize(Queue* pq); //判断队列是否为空 bool QueueEmpty(Queue* pq);void QueueInit(Queue* pq) {assert(pq);pq-head pq-tail NULL; } void QueueDestory(Queue* pq) {assert(pq);QNode* cur pq-head;while (cur){QNode* next cur-next;free(cur);cur next;}pq-head pq-tail NULL;//返回初始状态 } //队尾入 void QueuePush(Queue* pq, QDataType x) {assert(pq);QNode* newnode (QNode*)malloc(sizeof(QNode));if (newnode NULL){printf(malloc fail\n);exit(-1);}newnode-data x;newnode-next NULL;if (pq-tail NULL){pq-head pq-tail newnode;}else{pq-tail-next newnode;pq-tail newnode;}} //队头出 void QueuePop(Queue* pq) {assert(pq);assert(pq-head);//断言队列是否为空为空就不可删除会有野指针if (pq-head-next NULL)//当只有一个节点时tail可能为野指针tail指向已释放的空间pq-tail NULL;QNode* next pq-head-next;free(pq-head);pq-head next;} //取队头的数据 QDataType QueueFront(Queue* pq) {assert(pq);assert(pq-head);return pq-head-data; } //取队尾的数据 QDataType QueueBack(Queue* pq) {assert(pq);assert(pq-head);return pq-tail-data; } //取数据的个数 int QueueSize(Queue* pq) {assert(pq);int size 0;QNode* cur pq-head;while (cur){size;cur cur-next;}return size; } //判断队列是否为空 bool QueueEmpty(Queue* pq) {assert(pq);return pq-head NULL; } 通过队列创建栈 typedef struct {Queue q1;Queue q2; }MyStack; MyStack* myStackCreate() {MyStack* ps (MyStack*)malloc(sizeof(MyStack));if (ps NULL){printf(malloc fail\n);exit(-1);}QueueInit(ps-q1);//对队列进行初始化QueueInit(ps-q2);return ps; } 在栈顶添加数据 添加数据时要在不为空的队列里添加 void myStackPush(MyStack* obj, int x) {if (!QueueEmpty(obj-q1)){QueuePush(obj-q1,x);}else{QueuePush(obj-q2, x);} } 从栈顶处删除数据并返回第一个数据 int myStackPop(MyStack* obj) {Queue* emptyQ obj-q1;Queue* nonemptyQ obj-q2;if (!QueueEmpty(obj-q1)){emptyQobj-q2;nonemptyQobj-q1;}//倒数据while (QueueSize(nonemptyQ) 1){//将不空的队列的头拷贝至空队列中QueuePush(emptyQ, QueueFront(nonemptyQ));QueuePop(nonemptyQ);//删除头数据}int top QueueFront(nonemptyQ);QueuePop(nonemptyQ);//删除最后一个数据实现了后进先出return top; } 取栈顶的数据 取不为空的队列的队尾数据 int myStackTop(MyStack* obj) {if (!QueueEmpty(obj-q1)){return QueueBack(obj-q1);}else{return QueueBack(obj-q2);} } 判断栈是否为空 bool myStackEmpty(MyStack* obj) {return QueueEmpty(obj-q1) QueueEmpty(obj-q2); } 释放栈 先销毁队列再释放。 void myStackFree(MyStack* obj) {QueueDestory(obj-q1);QueueDestory(obj-q2);free(obj); } 整体代码 #includestdio.h #includestdbool.h #includeassert.h #includestdlib.h typedef int QDataType; typedef struct QueueNode {struct QueueNode* next;QDataType data; }QNode;//删除数据和插入数据需要记录头结点和尾结点 typedef struct Queue {QNode* head;QNode* tail; }Queue; void QueueInit(Queue* pq); void QueueDestory(Queue* pq); //队尾入 void QueuePush(Queue* pq, QDataType x); //队头出 void QueuePop(Queue* pq); //取队头的数据 QDataType QueueFront(Queue* pq); //取队尾的数据 QDataType QueueBack(Queue* pq); //取数据的个数 int QueueSize(Queue* pq); //判断队列是否为空 bool QueueEmpty(Queue* pq);void QueueInit(Queue* pq) {assert(pq);pq-head pq-tail NULL; } void QueueDestory(Queue* pq) {assert(pq);QNode* cur pq-head;while (cur){QNode* next cur-next;free(cur);cur next;}pq-head pq-tail NULL;//返回初始状态 } //队尾入 void QueuePush(Queue* pq, QDataType x) {assert(pq);QNode* newnode (QNode*)malloc(sizeof(QNode));if (newnode NULL){printf(malloc fail\n);exit(-1);}newnode-data x;newnode-next NULL;if (pq-tail NULL){pq-head pq-tail newnode;}else{pq-tail-next newnode;pq-tail newnode;}} //队头出 void QueuePop(Queue* pq) {assert(pq);assert(pq-head);//断言队列是否为空为空就不可删除会有野指针if (pq-head-next NULL)//当只有一个节点时tail可能为野指针tail指向已释放的空间pq-tail NULL;QNode* next pq-head-next;free(pq-head);pq-head next;} //取队头的数据 QDataType QueueFront(Queue* pq) {assert(pq);assert(pq-head);return pq-head-data; } //取队尾的数据 QDataType QueueBack(Queue* pq) {assert(pq);assert(pq-head);return pq-tail-data; } //取数据的个数 int QueueSize(Queue* pq) {assert(pq);int size 0;QNode* cur pq-head;while (cur){size;cur cur-next;}return size; } //判断队列是否为空 bool QueueEmpty(Queue* pq) {assert(pq);return pq-head NULL; } typedef struct {Queue q1;Queue q2; }MyStack; MyStack* myStackCreate() {MyStack* ps (MyStack*)malloc(sizeof(MyStack));if (ps NULL){printf(malloc fail\n);exit(-1);}QueueInit(ps-q1);QueueInit(ps-q2);return ps; } void myStackPush(MyStack* obj, int x) {if (!QueueEmpty(obj-q1)){QueuePush(obj-q1,x);}else{QueuePush(obj-q2, x);} } //删除数据且返回栈顶 int myStackPop(MyStack* obj) {Queue* emptyQ obj-q1;Queue* nonemptyQ obj-q2;if (!QueueEmpty(obj-q1)){emptyQobj-q2;nonemptyQobj-q1;}//倒数据while (QueueSize(nonemptyQ) 1){//将不空的队列的头拷贝至空队列中QueuePush(emptyQ, QueueFront(nonemptyQ));QueuePop(nonemptyQ);//删除头数据}int top QueueFront(nonemptyQ);QueuePop(nonemptyQ);//删除最后一个数据实现了后进先出return top; }int myStackTop(MyStack* obj) {if (!QueueEmpty(obj-q1)){return QueueBack(obj-q1);}else{return QueueBack(obj-q2);} } bool myStackEmpty(MyStack* obj) {return QueueEmpty(obj-q1) QueueEmpty(obj-q2); } void myStackFree(MyStack* obj) {QueueDestory(obj-q1);QueueDestory(obj-q2);free(obj); }
http://www.yutouwan.com/news/81688/

相关文章:

  • 租用网站服务器价格网站源码建设模板
  • 河南营销型网站网站改版策划方案
  • 在家给别人做网站合法吗在百度如何发布作品
  • c2c网站代表和网址更改域名代理商对网站有影响吗
  • wordpress当下载站不同域名一样的网站
  • 黑龙江建设人员证件查询网站wordpress快速发布
  • 华强北 网站建设wordpress 分类 评论
  • 河北省网络科技网站网站界面设计规划
  • 手机网站 用户体验有什么网站可以做微信app
  • 网站建设费算不算固定资产ui设计软件下载
  • 上海网站设计团队wordpress标签关注
  • 做违法网站程序员犯法吗天津港建设公司官网
  • 公司网站如何做分录孝感网站建设xgsh
  • 免费cms网站管理系统学做各种糕点的网站
  • 网站优化工作怎么样湖南手机版建站系统哪个好
  • 小网站建设装修公司哪家好一些呢
  • 郑州做网站优化四川建设厅官方网站九大员通知
  • mvc做门户网站建设项目验收在哪个网站公示
  • 信用网站标准化建设方案车网站模板预览
  • django 电商网站开发58同城石家庄网站建设
  • 铜山区建设局招投标网站内蒙古包头网站建设
  • wordpress 上传网站吗想制作自己的网站吗
  • 计算机学院网站建设系统可行性分析电商网站怎么做聚合
  • 外贸响应式网站设计请人做网站收费
  • 用pc做网站服务器为什么不如云主机老河口网站
  • 资讯网站优化排名如何自己建一个公司网站
  • 义乌网络科技有限公司专业网站seo优化公司
  • 山西推广型网站建设中餐网站模板
  • 网站引用优酷咨询公司工资一般多少
  • 网站建设进度控制铜川网络推广