栈的基本操作
2016-04-28 09:08
267 查看
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
#define SizeMax 105
typedef char ElemType;
typedef struct
{
ElemType data[SizeMax];
int top;
} SqStack;
void InitStack(SqStack *&s) //建立栈
{
s=(SqStack*)malloc(sizeof(SqStack));
memset(s->data,0,sizeof(SqStack));
s->top=-1;
}
int StackEmpty(SqStack *s) //判断是否为空
{
return s->top==-1;
}
void Push(SqStack *&s,ElemType x) //把x元素压入栈
{
s->top++;
s->data[s->top]=x;
}
int Length(SqStack *s) //输出长度
{
return s->top+1;
}
void PrintStack(SqStack *s) //输出栈
{
for(int i=(int)strlen(s->data)-1; i>=0; i--)
printf("%c",s->data[i]);
printf("\n");
}
void Print(SqStack *s) // //输出栈
{
PrintStack(s);
}
void DestroyStack(SqStack *&s)//销毁栈
{
free(s);
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
#define SizeMax 105
typedef char ElemType;
typedef struct
{
ElemType data[SizeMax];
int top;
} SqStack;
void InitStack(SqStack *&s) //建立栈
{
s=(SqStack*)malloc(sizeof(SqStack));
memset(s->data,0,sizeof(SqStack));
s->top=-1;
}
int StackEmpty(SqStack *s) //判断是否为空
{
return s->top==-1;
}
void Push(SqStack *&s,ElemType x) //把x元素压入栈
{
s->top++;
s->data[s->top]=x;
}
int Length(SqStack *s) //输出长度
{
return s->top+1;
}
void PrintStack(SqStack *s) //输出栈
{
for(int i=(int)strlen(s->data)-1; i>=0; i--)
printf("%c",s->data[i]);
printf("\n");
}
void Print(SqStack *s) // //输出栈
{
PrintStack(s);
}
void DestroyStack(SqStack *&s)//销毁栈
{
free(s);
}
相关文章推荐
- 项目1-深复制体验(1)
- [剑指offer]二叉搜索树的后序遍历序列
- 第九周项目二我的数组类
- 多行编辑软件
- 剑指offer 二叉树的深度
- Netty in Action (二十四) 第十三章节 UDP的广播事件
- 解决Serv-U服务停止的方法
- 顺序表的基本操作
- 第9周项目2:我的数组类
- SQL之merge
- Linux下四款Web服务器压力测试工具(http_load、webbench、ab、siege)介绍
- RSA签名和验签过程
- swust OJ 1400 8数码问题
- 如何改变UITextField中placeholder的颜色,字体
- 真伪静态网站优缺点分析
- python模拟登录博客园并爬取用户粉丝数
- 深入学习block
- tomcat服务器配置字符集为utf-8-彻底解决中文乱码问题
- Netty in Action (二十三) 第十二章节 WebSocket
- 将poll程序改为epoll实现