c语言实现栈的增删查减
#include"stdio.h"
#include"stdlib.h"
#define STACK_SIZE 100
#define STACKINCREMENT 10
typedef struct{
int *base;
int *top;
int stacksize;
}Stack;
//初始化
int InitStack(Stack &S){
S.base=(int *)malloc(STACK_SIZE * sizeof(int));
if(!S.base)
return 0;
S.top=S.base;
S.stacksize=STACK_SIZE;
return 1;
}
//销毁
void DesStack(Stack &S){
S.top=S.base;
free(S.base);
S.base = NULL;
S.top = NULL;
S.stacksize = 0;
printf("1");
}
//置空
void ClearStack(Stack &S){
S.top=S.base;
}
//判空
bool StackEmpty(Stack &S){
if(S.base==S.top)
return true;
else
return false;
}
//长度
int StackLen(Stack &S){
return S.top - S.base;
}
//获取
int GetTop(Stack &S){
return *(S.top-1);
}
//进栈
int Push(Stack &S,int e){
if(S.top-S.base>=S.stacksize){
S.base = (int *)realloc(S.base,(S.stacksize + STACKINCREMENT)*sizeof(int));
if(!S.base) return 0;
S.top = S.base + S.stacksize;
S.stacksize += STACKINCREMENT;
}
*S.top++=e;
return 1;
}
//删除栈顶
int Pop(Stack &S){
return *--S.top;
}
//输出
void StackTraverse(Stack &S){
int *p=NULL;
p=S.top;
while(p!=S.base){
p--;
printf("%d",*p);
}
}
void main(){
Stack S;
printf("初始化:");
printf("%d\n",InitStack(S));
printf("入栈");
Push(S,1);
Push(S,2);
Push(S,3);
Push(S,4);
Push(S,5);
printf("输出");
StackTraverse(S);
printf("长度");
printf("%d",StackLen(S));
printf("获取栈顶");
printf("%d",GetTop(S));
printf("删除并获取栈顶");
printf("%d",Pop(S));
printf("长度");
printf("%d",StackLen(S));
printf("判空");
StackEmpty(S);
printf("置空");
ClearStack(S);
printf("判空");
StackEmpty(S);
DesStack(S);
}
//定义宏时不能加分号
c语言实现栈的增删查减的更多相关文章
- 基于.net的分布式系统限流组件 C# DataGridView绑定List对象时,利用BindingList来实现增删查改 .net中ThreadPool与Task的认识总结 C# 排序技术研究与对比 基于.net的通用内存缓存模型组件 Scala学习笔记:重要语法特性
基于.net的分布式系统限流组件 在互联网应用中,流量洪峰是常有的事情.在应对流量洪峰时,通用的处理模式一般有排队.限流,这样可以非常直接有效的保护系统,防止系统被打爆.另外,通过限流技术手段,可 ...
- 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
- 8天学通MongoDB——第二天 细说增删查改
原文地址:http://www.cnblogs.com/huangxincheng/archive/2012/02/19/2357846.html 看过上一篇,相信大家都会知道如何开启mongodb了 ...
- TP框架 增删查
TP框架添加数据到数据库1.使用数组方式添加造模型对象 2.使用AR方式 强类型语言存在的方式 3.使用自动收集表单添加 :只能用POST方式,提交数据一个操作方法实现两个逻辑:A显示页面B得到数据 ...
- 在MVC中使用泛型仓储模式和依赖注入实现增删查改
标签: 原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository ...
- Mysql常用增删查改及入门(二)
常用:数据库常用就是DML:增删查改 1.增加数据: insert into 表名 values (值1,值2...); insert into 表名 (字段1,字段2) values (值1,值2) ...
- golang使用json格式实现增删查改
需求和思路 在一般的小项目或者一个小软件,例如客户端之类的小程序中,可能会需要数据的持久化.但是使用一般的数据库(Mysql)之类的不合适.使用sqlite3这种嵌入式的是个较好的方法,但是Go语言中 ...
- C语言实现栈代码
/* 栈的特性:先进后出. 栈在计算语言处理和将递归算法改为非递归算法等方面起着非常重要的作用. */ #define INITSIZE 100 //储存空间的初始分配量 typedef int El ...
- 学习记录——使用PHP实现数据增删查改等基本功能(前后端分离)
萌新初次学习服务器端语言,分享学习经验 实现功能:1.显示数据表 2.对数据进行分页 3.对数据进行增删查改 由于本萌新采用前后端完全分离方案,所以数据传输用的ajax,为了提高代码的复用 ...
随机推荐
- markdown的图片外链
markdown的图片用本地的很不方便,今天试用了一下七牛的服务,感觉很好用.推荐一下,免费的服务够用并且比较友好.
- Schwartz kernel theorem施瓦兹核定理
In mathematics, the Schwartz kernel theorem is a foundational result in the theory of generalized fu ...
- (转)Linux环境进程间通信系列(五):共享内存
原文地址:http://www.cppblog.com/mydriverc/articles/29741.html 共享内存可以说是最有用的进程间通信方式,也是最快的 IPC 形式.两个不同进程 A ...
- wpf附加属性理解
WPF附加属性 http://www.cnblogs.com/tianyou/archive/2012/12/27/2835670.html WPF属性(二)附加属性 http://blog.csdn ...
- 使用JMeter测试基于WebSocket协议的服务
使用JMeter测试基于WebSocket协议的服务 :first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba( ...
- Android getDimension,getDimensionPixelOffset,getDimensionPixelSize
1.例如在onMeasure(int , int)方法中可能要获取自定义属性的值.如: TypedArray a = context.obtainStyledAttributes(attrs, R.s ...
- Glib学习笔记(四)
你将学到什么 使用GObject模拟实现接口 使用接口 首先按照学习笔记(一)定义一个普通的GObject类 使用G_DEFINE_TYPE_WITH_CODE和G_IMPLEMENT_INTERFA ...
- React进阶篇(2) -- Redux
前言 如果还不知道为什么要使用Redux,说明你暂时还不需要它. 三大原则 单一数据源 整个应用的 state 被储存在一棵 object tree 中,并且这个 object tree 只存在于唯一 ...
- Spring boot进阶-配置Controller、interceptor...
1.配置SpringBootApplication(对spring boot来说这是最基本) package io.github.syske.springboot31; import org.spri ...
- cf555e
cf555e(缩点) 给一个 n 个点 m 条边的图,以及 q 对点 (s,t),让你给 m 条边定向.问是否存在一种方案,使每对点的 s 能走到 t. \(n,m,q≤ 2×10^5\). 首先,在 ...