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

如何用phpstudy做网站电商运营怎么自学

如何用phpstudy做网站,电商运营怎么自学,wordpress过去指定分类文章,上海网站设计优刻1.栈的初始化 2.入栈 3.出栈 4.取出栈顶元素 5.获取栈中有效元素个数 6.栈的销毁 栈:⼀种特殊的线性表,其只允许在固定的⼀端进⾏插⼊和删除元素操作。进⾏数据插⼊和删除操作 的⼀端称为栈顶,另⼀端称为栈底。栈中的数据元素遵守后进先…

1.栈的初始化

2.入栈

3.出栈

4.取出栈顶元素

5.获取栈中有效元素个数

6.栈的销毁


栈:⼀种特殊的线性表,其只允许在固定的⼀端进⾏插⼊和删除元素操作。进⾏数据插⼊和删除操作 的⼀端称为栈顶,另⼀端称为栈底。栈中的数据元素遵守后进先出LIFO(LastInFirstOut)的原则。

压栈:栈的插⼊操作叫做进栈/压栈/⼊栈,⼊数据在栈顶。

出栈:栈的删除操作叫做出栈。出数据也在栈顶

1.栈的初始化

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>//定义
typedef int STDataType;
struct Stack
{STDataType* arr;int capacity;  int top;  //记录栈顶元素
};
typedef struct Stack ST;//栈的初始化
void STInit(ST* ps)
{ps->arr = NULL;ps->capacity = 0;ps->top = 0;
}


2.入栈

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>//定义
typedef int STDataType;
struct Stack
{STDataType* arr;int capacity;  int top;  //记录栈顶元素
};
typedef struct Stack ST;//入栈
void STPush(ST* ps, STDataType x)
{assert(ps);if (ps->top == ps->capacity)//判断内存是否够 --- 如果栈顶等于栈容量大小,那么就需要扩容{int newcapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;STDataType* tmp = (STDataType*)realloc(ps->arr, newcapacity *sizeof(STDataType));if (tmp == NULL)//如果申请失败,则perror{perror("realloc fail");exit(1);}ps->capacity = newcapacity;ps->arr = tmp;}ps->arr[ps->top++] = x;//入栈
}

3.出栈

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>//定义
typedef int STDataType;
struct Stack
{STDataType* arr;int capacity;  int top;  //记录栈顶元素
};
typedef struct Stack ST;//判断栈是否为空
bool STEmpty(ST* ps)
{assert(ps);return ps->top == 0;//如果为0,则返回true,不为0返回false
}//出栈
void STPop(ST* ps)
{assert(!STEmpty(ps));//记得要取反 --- 栈不为空才可以出栈,否则就是非法访问--ps->top;//对栈顶--即可
}

4.取出栈顶元素

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>//定义
typedef int STDataType;
struct Stack
{STDataType* arr;int capacity;  int top;  //记录栈顶元素
};
typedef struct Stack ST;//判断栈是否为空
bool STEmpty(ST* ps)
{assert(ps);return ps->top == 0;//如果为0,则返回true,不为0返回false
}//取出栈顶元素
STDataType STTop(ST* ps)
{assert(!STEmpty(ps));//栈不为空才可以取栈顶 --- 否则就是非法访问
//方法一// STDataType tmp = ps->arr[ps->top - 1];// STPop(ps);// return tmp;
//方法二return ps->arr[ps->top - 1];
}

5.获取栈中有效元素个数

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>//定义
typedef int STDataType;
struct Stack
{STDataType* arr;int capacity;  int top;  //记录栈顶元素
};
typedef struct Stack ST;//获取栈中有效元素个数
int STSize(ST* ps)
{assert(ps);return ps->top;//我们在出栈和入栈都有记录top,所以直接返回top就是栈的有效元素个数
}

6.栈的销毁

//栈的销毁
void STDestroy(ST* ps)
{if (ps->arr)//如果ps->arr不为空,那么进入if,释放ps{free(ps->arr);}ps->arr = NULL;//置为空,避免成为野指针ps->capacity = 0;ps->top = 0;
}

http://www.dtcms.com/wzjs/76671.html

相关文章:

  • 百度云主机做网站廊坊百度快照优化
  • 网站关键词怎么做排名靠前semester什么意思
  • 传播易网站开发方案水果网络营销策划方案
  • 大连淘宝网站建设短视频平台推广方案
  • 哪个网站可以做魔方图片大全关键词查询工具哪个好
  • 淘宝客网站怎么做推广影视剪辑培训机构排名
  • 自己做的旅游网站 介绍网上销售都有哪些平台
  • wordpress多筛选徐州seo网站推广
  • 劲松做网站的公司seo外包公司多吗
  • 网站建设公司小程序基础建站如何提升和优化
  • 免费 网站 平台google官方下载
  • 台州外贸网站磁力链最好用的搜索引擎
  • 沈阳妇科排名前十的医院长沙官网seo技术厂家
  • 找人做网站维护多少钱优化器
  • 全栈网站开发工程师广东东莞最新疫情
  • 网站开发需求说明网络营销模式有哪些
  • 成都flash互动网站开发网络营销的市场背景
  • 做网站的材料今日关键词
  • 网站搭建为什么要备案网络推广网站排行榜
  • 官方网站下载官方版本网站模板库
  • 武汉网站优化方案网络推广员岗位职责
  • 企业网络营销策略分析案例长沙seo推广
  • 如何做网站ppt百度小说风云榜首页
  • 政府网站建设上会说明网站下载免费软件
  • 免备案域名是什么seo接单
  • 常用来做网站首页的是查网站权重
  • 贸易有限公司安卓优化大师手机版
  • 模版建站怎么建网站免费的
  • 苏州园区手机网站制作国内新闻大事20条
  • 东莞外贸建站模板推广游戏赚钱的平台