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

书本翻页 网站模板杭州下沙做网站的论坛

书本翻页 网站模板,杭州下沙做网站的论坛,做系统哪个网站上的好,四川住房和城乡建设厅网站咨询电话题目 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作#xff08;push、pop、peek、empty#xff09;#xff1a; 实现 MyQueue 类#xff1a; void push(int x) 将元素 x 推到队列的末尾int pop() 从队列的开头移除并返回元素int peek() 返回队列开…题目 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作push、pop、peek、empty 实现 MyQueue 类 void push(int x) 将元素 x 推到队列的末尾int pop() 从队列的开头移除并返回元素int peek() 返回队列开头的元素boolean empty() 如果队列为空返回 true 否则返回 false 题解 根据栈后进先出的性质可将两个栈分别设置为只压入元素的栈和只弹出元素的栈以此来满足队列先进先出的性质。 代码如下 #include stdio.h #include stdlib.h #include assert.h #include errno.h #include stdbool.htypedef 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-top 0; //指向栈顶元素的下一个位置pst-capacity 0; }void STDestroy(ST* pst) {assert(pst);free(pst-a);pst-a NULL;pst-top 0;pst-capacity 0; }void STPush(ST* pst, STDataType x) {if (pst-top pst-capacity){int newcapacity pst-capacity 0 ? 4 : pst-capacity * 2;STDataType* tmp (STDataType*)realloc(pst-a, newcapacity * sizeof(STDataType));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(!STEmpty(pst));pst-top--; }STDataType STTop(ST* pst) {assert(pst);assert(!STEmpty(pst));return pst-a[pst-top - 1]; }bool STEmpty(ST* pst) {assert(pst);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 myQueuePeek(MyQueue* obj) {if(STEmpty(obj-popst)){while(!STEmpty(obj-pushst)){STPush(obj-popst,STTop(obj-pushst));STPop(obj-pushst);}}return STTop(obj-popst); }int myQueuePop(MyQueue* obj) {int front myQueuePeek(obj);STPop(obj-popst);return front; }bool myQueueEmpty(MyQueue* obj) {return STEmpty(obj-pushst) STEmpty(obj-popst); }void myQueueFree(MyQueue* obj) {STDestroy(obj-pushst);STDestroy(obj-popst);free(obj); }
http://www.zqtcl.cn/news/511396/

相关文章:

  • 做系统软件的网站wordpress网站会员太多
  • 上海门户网站怎么登录网站开发竞价单页
  • 东莞市外贸网站建设公司软件开发 系统开发 网站开发服务
  • 泉州制作网站设计南宁网站排名外包
  • 南通网站建设入门wordpress google seo
  • 怎么建立图片的网站吗网站响应式是什么意思
  • 网站建设买了服务器后怎么做WordPress多城市
  • 网站建设凭证成都网站设计公司
  • 创新创业营销策略网站建设等做钢材的都用什么网站
  • 英文免费网站模板大庆+网站建设
  • 品牌网站建设内容框架网站首页收录没了
  • 湖南城乡住房建设厅网站网站图片切换效果
  • 凡科做的网站可以在百度搜到吗阿里云nas做网站
  • 做企业销售分析的网站更改wordpress传文件尺寸
  • 网站建设策划书封面知名企业名称
  • 中小企业网站建设与管理课件百度云济南高端网站建设公司
  • 台州企业建站程序网页设计素材网站知乎
  • wordpress视频付费谷歌seo专员是指什么意思
  • 域名续费做网站wordpress模板淘宝客模板
  • 加强政协机关网站建设深圳教育软件app开发
  • 绍兴企业网站推广Django 个人博客网站开发
  • html5 开发网站图门市建设局网站
  • wordpress 建立网站江苏电信网站备案
  • 企业网站能个人备案吗成都蜀美网站建设
  • 网站开发 占位符直播网站开发接入视频
  • 网站 易用性原则义乌进货网平台
  • 做网站的你选题的缘由是什么洛阳网站建设找汉狮
  • 常德住房和城乡建设局网站陕西省建设厅的网站
  • 国外做meta分析的网站开发公司替业主承担物业费承诺书
  • 百度收录网站定位地址wordpress 检测浏览器