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

免费作图网站都有哪些广州十大活动策划公司

免费作图网站都有哪些,广州十大活动策划公司,顺德网站建设教程,网站建设的平台分析题目描述 题目链接#xff1a;232. 用栈实现队列 - 力扣#xff08;LeetCode#xff09; 题目分析 我们先把之前写的数组栈的实现代码搬过来 用栈实现队列最主要的是实现队列先进先出的特点#xff0c;而栈的特点是后进先出#xff0c;那么我们可以用两个栈来实现…题目描述 题目链接232. 用栈实现队列 - 力扣LeetCode 题目分析 我们先把之前写的数组栈的实现代码搬过来 用栈实现队列最主要的是实现队列先进先出的特点而栈的特点是后进先出那么我们可以用两个栈来实现 一个pushst用来入队列一个popst用来出队列 具体的接口有下面几个 初始化 malloc一块空间来存两个栈同时初始化这两个栈 入队列 入数据都入到pushst 出队列 出数据前先需要导数据当popst为空且pushst不为空的时候pushst的top数据依次push到popst中然后返回pop的top数据然后pop掉top数据如果pop不为空则直接返回poptop并pop 返回队头数据 判空 两个栈同时为空则为空 销毁  销毁还是依次销毁 代码示例 #include stdio.h #include stdlib.h #include assert.h #include stdbool.h typedef int STDataType; typedef struct Stack {STDataType* a;int top;//标识栈顶位置int capacity; }ST; //初始化 void STInit(ST* pst); //销毁 void STDestroy(ST* pst); //入栈 void STPush(ST* pst, STDataType x); //出栈 void STPop(ST* pst); //返回栈顶元素 STDataType STTop(ST* pst); //判空 bool STEmpty(ST* pst); //栈的元素个数 int STSize(ST* pst);//初始化 void STInit(ST* pst) {assert(pst);pst-a NULL;pst-capacity 0;pst-top 0; } //销毁 void STDestroy(ST* pst) {assert(pst);free(pst-a);pst-a NULL;pst-top pst-capacity 0; } //入栈 void STPush(ST* pst, STDataType x) {assert(pst);if (pst-top pst-capacity){int newcapacity pst-capacity 0 ? 4 : pst-capacity * 2;STDataType* tmp (STDataType * )realloc(pst-a, sizeof(STDataType) * newcapacity);if (tmp NULL){perror(realloc fail);return;}pst-a tmp;pst-capacity newcapacity;}pst-a[pst-top] x;pst-top; } //出栈 void STPop(ST* pst) {assert(pst);assert(pst-top 0);pst-top--; } //返回栈顶元素 STDataType STTop(ST* pst) {assert(pst);assert(pst-top 0);return pst - a[pst-top - 1]; } //判空 bool STEmpty(ST* pst) {assert(pst);/*if (pst-top 0){return true;}else{return false;}*/return pst-top 0; } //栈的元素个数 int STSize(ST* pst) {assert(pst);return pst-top; }typedef struct {ST pushst;ST popst; } MyQueue;MyQueue* myQueueCreate() {MyQueue* obj(MyQueue*)malloc(sizeof(MyQueue));STInit((obj-pushst));STInit((obj-popst));return obj; }void myQueuePush(MyQueue* obj, int x) {STPush((obj-pushst),x); }int myQueuePop(MyQueue* obj) {int frontmyQueuePeek(obj);STPop((obj-popst));return front; }int myQueuePeek(MyQueue* obj) {if(STEmpty((obj-popst))){while(!STEmpty((obj-pushst))){STPush((obj-popst),STTop((obj-pushst))); STPop((obj-pushst));}}return STTop((obj-popst)); }bool myQueueEmpty(MyQueue* obj) {return STEmpty((obj-pushst))STEmpty((obj-popst)); }void myQueueFree(MyQueue* obj) {STDestroy((obj-pushst));STDestroy((obj-popst));free(obj); }/*** Your MyQueue struct will be instantiated and called as such:* MyQueue* obj myQueueCreate();* myQueuePush(obj, x);* int param_2 myQueuePop(obj);* int param_3 myQueuePeek(obj);* bool param_4 myQueueEmpty(obj);* myQueueFree(obj); */
http://www.dnsts.com.cn/news/188167.html

相关文章:

  • 甘肃建设职工教育培训中心网站网架公司
  • 网站开发培训是不是坑f2c网站建设
  • 市城乡规划建设局网站wordpress网站目录
  • 沂源网站制作长沙专业做网络的公司
  • 网站模版怎么上传到空间深圳网络工程公司
  • 做网店网站交易网站建设具体方案
  • seo外包优化网站wordpress菜单链接新窗口
  • 网站开发流程中客户的任务是什么18末年年禁止观看网站
  • 建立网站怎么申请wordpress怎么添加标签页
  • 网页设计设计一个网站首页mysql 视频网站开发
  • 网站推广方式主要通过wordpress代码实现头像
  • 青岛网站设计公司联系方式phpcms v9 网站搬家
  • 珠海网站公司seo网站推广优化就找微源优化
  • win7局域网网站建设vs2010网站开发
  • 建设银行在上海的招聘网站短网址在线生成哪个好
  • 建外文网站电商平台建设
  • 江西省建设培训中心网站简约 个人网站
  • 好买卖做网站网络推广软件赚钱
  • 建网站 xyz建设标准网站
  • 唐山自助建站网站备案为何要关站
  • 广州wap网站建设排行榜百度
  • 上海人才网志鸿优化网官网
  • 手机网站判断跳转代码怎么写二级域名建立网站
  • wordpress网站的跳出率很低社区建立网站
  • 流行网站开发工具设计在线中国
  • 毕业设计资源网站淘宝官网首页网站
  • 红酒网站建设模板防红短链接生成
  • 私人做网站a网站设计英文翻译
  • 网站建设满意度调查问卷做网站怎么制作
  • 北京网站建设知名公司排名html的网站模板