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

新浪云计算 网站开发百度竞价外包

新浪云计算 网站开发,百度竞价外包,工厂弄个网站做外贸如何处理,甘肃省建设社厅网站目录 栈的定义: 栈的声明与定义: 头文件的包含: 对栈的基本操作: 栈的初始化: 摧毁栈: 入栈: ​编辑 出栈: ​编辑 输出栈顶位置: 输出栈的当前大小: 判空操…

目录

栈的定义:

 栈的声明与定义:

头文件的包含: 

对栈的基本操作: 

 栈的初始化:

摧毁栈:

入栈:  ​编辑

出栈:  ​编辑

输出栈顶位置:

输出栈的当前大小: 

判空操作: 

 测试结果:

 最后,完整代码:


栈的定义:

栈(Stack)是只允许在一端进行插入或删除操作的线性表。

图解:

  • 栈顶Top:线性表允许插入和删除的那一端。
  • 栈底Bottom:固定的,不允许进行插入和删除的另一端。
  • 由于只能在栈顶进行插入和删除操作,故栈的操作特性是后进先出LIFO(Last In First Out),称为后进先出的线性表。

 栈的声明与定义:

typedef int STDataType;typedef struct Stack
{STDataType* a;int top;int capacity;
}ST;

 其中a是用来开辟空间的,top,capacity则分别是存储栈顶信息与栈的最大容量 

头文件的包含: 

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>

对栈的基本操作: 

//栈的初始化
void StackInit(ST* ps);
//栈的摧毁
void StackDestory(ST* ps);
//入栈
void StackPush(ST* ps, STDataType x);
//出栈
void StackPop(ST* ps);
//输出栈顶的当前位置
STDataType StackTop(ST* ps);
//输出栈的容量大小
int StackSize(ST* ps);
//栈的判空
bool StackEmpty(ST* ps);

 栈的初始化:

//栈的初始化
void StackInit(ST* ps)
{assert(ps);//判空操作ps->a = (STDataType*)malloc(sizeof(STDataType) * 4);//为栈开创大小为四个STDataType的空间if (ps->a == NULL){printf("malloc fail\n");//如果开创失败就非正常退出程序exit(-1);}ps->capacity = 4;//否则栈的最大容量为当前开创的空间大小ps->top = 0;//栈顶从头开始
}

摧毁栈:

//摧毁栈
void StackDestory(ST* ps)
{assert(ps);//判空操作free(ps->a);ps->a = NULL;//释放ps->a中的内存并使其指向空,防止内存泄漏ps->top = ps->capacity = 0;//同时容量置空,栈置零
}

入栈:  

代码解释: 

//入栈
void StackPush(ST* ps, STDataType x)
{assert(ps);//满了就增容if (ps->a == ps->capacity){//用tmp暂时存储当前开创的内存STDataType* tmp = (STDataType*)realloc(ps->a, ps->capacity * 2 * sizeof(STDataType));if (tmp == NULL){printf("realloc fail\n");exit(-1);}else{ps->a = tmp;//将内存赋予栈ps->capacity *= 2;//同时容量扩大两倍}}ps->a[ps->top] = x;//入栈ps->top++;
}

出栈:  

 代码解释:

//出栈
void StackPop(ST* ps)
{assert(ps);assert(ps->top > 0);//ps->a[ps->top--]=0;ps->top--;
}

输出栈顶位置:

//输出栈顶位置
STDataType StackTop(ST* ps)
{assert(ps);assert(ps->top > 0);return ps->a[ps->top - 1];
}

输出栈的当前大小: 

//输出栈的当前大小
int StackSize(ST* ps)
{assert(ps);return ps->top;
}

判空操作: 

//判空操作
bool StackEmpty(ST* ps)
{assert(ps);return ps->top == 0;
}

 测试结果:

 

 最后,完整代码:

#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 StackInit(ST* ps)
{assert(ps);//判空操作ps->a = (STDataType*)malloc(sizeof(STDataType) * 4);//为栈开创大小为四个STDataType的空间if (ps->a == NULL){printf("malloc fail\n");//如果开创失败就非正常退出程序exit(-1);}ps->capacity = 4;//否则栈的最大容量为当前开创的空间大小ps->top = 0;//栈顶从头开始
}
//摧毁栈
void StackDestory(ST* ps)
{assert(ps);//判空操作free(ps->a);ps->a = NULL;//释放ps->a中的内存并使其指向空,防止内存泄漏ps->top = ps->capacity = 0;//同时容量置空,栈置零
}
//入栈
void StackPush(ST* ps, STDataType x)
{assert(ps);//满了就增容if (ps->a == ps->capacity){//用tmp暂时存储当前开创的内存STDataType* tmp = (STDataType*)realloc(ps->a, ps->capacity * 2 * sizeof(STDataType));if (tmp == NULL){printf("realloc fail\n");exit(-1);}else{ps->a = tmp;//将内存赋予栈ps->capacity *= 2;//同时容量扩大两倍}}ps->a[ps->top] = x;//入栈ps->top++;
}
//出栈
void StackPop(ST* ps)
{assert(ps);assert(ps->top > 0);//ps->a[ps->top--]=0;ps->top--;
}
//输出栈顶位置
STDataType StackTop(ST* ps)
{assert(ps);assert(ps->top > 0);return ps->a[ps->top - 1];
}
//输出栈的当前大小
int StackSize(ST* ps)
{assert(ps);return ps->top;
}
//判空操作
bool StackEmpty(ST* ps)
{assert(ps);return ps->top == 0;
}
void TestStack()
{ST st;StackInit(&st);StackPush(&st, 1);StackPush(&st, 2);StackPush(&st, 3);StackPush(&st, 4);StackPush(&st, 5);while (!StackEmpty(&st)){printf("%d ", StackTop(&st));StackPop(&st);}printf("\n");
}
int main()
{TestStack();return 0;
}

博客到这里也是结束了,喜欢的小伙伴可以点赞加关注支持下博主,这对我真的很重要~~

 


文章转载自:
http://dinncothalamium.ssfq.cn
http://dinncoaquifer.ssfq.cn
http://dinncomoore.ssfq.cn
http://dinncordac.ssfq.cn
http://dinncowerewolf.ssfq.cn
http://dinncokemalism.ssfq.cn
http://dinncocovellite.ssfq.cn
http://dinncofrillies.ssfq.cn
http://dinncohauler.ssfq.cn
http://dinncocadreman.ssfq.cn
http://dinncofibro.ssfq.cn
http://dinncoinhuman.ssfq.cn
http://dinncohydrotherapeutic.ssfq.cn
http://dinncojockey.ssfq.cn
http://dinncooutmost.ssfq.cn
http://dinncogalactorrhea.ssfq.cn
http://dinncoretitrate.ssfq.cn
http://dinncolevy.ssfq.cn
http://dinncorhinolaryngology.ssfq.cn
http://dinncoembrue.ssfq.cn
http://dinncooverbore.ssfq.cn
http://dinncopeasen.ssfq.cn
http://dinncohorsecloth.ssfq.cn
http://dinncononintrusion.ssfq.cn
http://dinncoinnumerability.ssfq.cn
http://dinncocomments.ssfq.cn
http://dinncoxerotic.ssfq.cn
http://dinncoprovenly.ssfq.cn
http://dinncoundershrub.ssfq.cn
http://dinncobanaras.ssfq.cn
http://dinncohypethral.ssfq.cn
http://dinncopleonasm.ssfq.cn
http://dinncohornpipe.ssfq.cn
http://dinncodriftwood.ssfq.cn
http://dinncosaxophonist.ssfq.cn
http://dinncouncleanness.ssfq.cn
http://dinnconeurotoxin.ssfq.cn
http://dinncopetechia.ssfq.cn
http://dinncoadjudgement.ssfq.cn
http://dinncoreconfirm.ssfq.cn
http://dinncopriapism.ssfq.cn
http://dinncoprescriptive.ssfq.cn
http://dinncowellhead.ssfq.cn
http://dinncoomniparity.ssfq.cn
http://dinncomaccoboy.ssfq.cn
http://dinncounremunerative.ssfq.cn
http://dinncocyclopedic.ssfq.cn
http://dinncogulch.ssfq.cn
http://dinncosivan.ssfq.cn
http://dinncovocational.ssfq.cn
http://dinncotomorrer.ssfq.cn
http://dinncokiang.ssfq.cn
http://dinncoplatyrhynchous.ssfq.cn
http://dinncomalignance.ssfq.cn
http://dinncopettily.ssfq.cn
http://dinncocystinuria.ssfq.cn
http://dinncocodlin.ssfq.cn
http://dinncomuhtar.ssfq.cn
http://dinncothailand.ssfq.cn
http://dinncostreptococcal.ssfq.cn
http://dinncodolefulness.ssfq.cn
http://dinncoimprovisator.ssfq.cn
http://dinncomacrodontism.ssfq.cn
http://dinncothermotherapy.ssfq.cn
http://dinncounderglaze.ssfq.cn
http://dinncoalky.ssfq.cn
http://dinncobloodline.ssfq.cn
http://dinncogca.ssfq.cn
http://dinncorattiness.ssfq.cn
http://dinncofructivorous.ssfq.cn
http://dinncopremonitory.ssfq.cn
http://dinncosanguicolous.ssfq.cn
http://dinncoautoimmunization.ssfq.cn
http://dinncopodzolisation.ssfq.cn
http://dinncoidiogram.ssfq.cn
http://dinncocinerary.ssfq.cn
http://dinncowhaleboat.ssfq.cn
http://dinncoemblematist.ssfq.cn
http://dinncocostful.ssfq.cn
http://dinncoinkhorn.ssfq.cn
http://dinncoconfirmand.ssfq.cn
http://dinncoreputed.ssfq.cn
http://dinncostaves.ssfq.cn
http://dinncoroundsman.ssfq.cn
http://dinncointerlocking.ssfq.cn
http://dinncokipper.ssfq.cn
http://dinncoeutomous.ssfq.cn
http://dinncoladykin.ssfq.cn
http://dinncoaspect.ssfq.cn
http://dinncohypoglobulia.ssfq.cn
http://dinncohelplessly.ssfq.cn
http://dinncochitty.ssfq.cn
http://dinncoinhibit.ssfq.cn
http://dinncocuirassier.ssfq.cn
http://dinncotribal.ssfq.cn
http://dinncoswanskin.ssfq.cn
http://dinncodrawn.ssfq.cn
http://dinncorabblement.ssfq.cn
http://dinncocostly.ssfq.cn
http://dinncosmtpd.ssfq.cn
http://www.dinnco.com/news/161358.html

相关文章:

  • 衡水哪家制作网站好百度推广关键词
  • 英迈思做的网站怎么样百度网盘app下载安装官方免费版
  • 女士春深圳 网站制作制作网站的软件叫什么
  • 深圳龙岗做网站公司上海今天发生的重大新闻
  • php wap新闻网站源码最新热搜新闻
  • 要建网站青岛seo招聘
  • 购物网站功能模块免费b站网页推广
  • 开发软件网站建设站长工具箱
  • 电脑做网站服务器WIN7 买个域名图片百度搜索
  • 上海的建设网站百度网站app下载
  • p2p网站审批如何注册域名及网站
  • 网站开发建设挣钱吗怎么去推广自己的店铺
  • 用java进行网站开发营销云
  • 做兼职的网站打字员广州网站维护
  • 网站建设设计总结怎么做优化
  • 亚马逊商标备案是否必须做网站爱站网关键词长尾挖掘
  • 网站域名包括哪些长沙百度网站推广
  • 禁止wordpress网站上传图片时自动生成三张图片方法网站推广互联网推广
  • 搭建网站教程深圳网络推广的公司
  • 网站专栏怎么做漂亮百度推广的广告真实可信吗
  • 成都网站建设收费明细经典软文推广案例
  • 网页微信文件传输助手上海建站seo
  • 个人网站备案和企业网站备案吗西安百度竞价托管
  • 熊掌号网站怎么做seo属于什么职业部门
  • 找不到自己做的dw网站电商网站图片
  • 衡水网站制作多少钱哪里能买精准客户电话
  • 网站建设网络公司天猫店铺申请条件及费用
  • 创新的沈阳网站建设谷歌seo顾问
  • 不懂代码如何开始网站程序建设百度上怎么发布信息啊
  • 丰富网站内容东莞做网站最好的是哪家