数据结构栈操作
来源:互联网 发布:起点传奇数据库编辑器 编辑:程序博客网 时间:2024/06/05 23:26
#include<stdio.h>
#define N 10
typedef int datatype;
typedef struct
{
datatype data[N];
int top;
}sqstack;
sqstack *creat_empty_sqstack()
{
sqstack *s;
s=(sqstack *)malloc(sizeof(sqstack));
s->top=-1; //-1表示空栈
return s;
}
int empty_stack(sqstack *s)
{
return -1==s->top;
}
int full_stack(sqstack *s)
{
return N-1==(*s).top;
}
void clear_stack(sqstack *s)
{
if(empty_stack(s))
{
printf("此栈已是空栈");
}
else
{
s->top=-1;
printf("清空成功!\n");
}
}
int lenth_stack(sqstack *s)
{
return s->top+1;
}
void push_stack(sqstack *s,datatype x)
{
if(full_stack(s))
{
printf("此栈已满!\n");
}
else
{
s->top=s->top+1;
if(N-1!=s->top)
{
s->data[s->top]=x;
printf("插入成功:%d\n",s->data[s->top]);
}
}
}
datatype pop_sqstack(sqstack *s)
{
if(empty_stack(s))
{
printf("空栈\n");
}
else
{
s->data[s->top]=0;
s->top=s->top-1;
}
}
datatype get_top(sqstack *s)
{
}
int main (int argc,char *argv[])
{
in
sqstack *s;
s=creat_empty_sqstack();
printf("判空:%d\n",empty_stack(s));
push_stack(s,200);
push_stack(s,400);
printf("lenth:%d\n",lenth_stack(s));
pop_sqstack(s);
printf("lenth:%d\n",lenth_stack(s));
printf("判满:%d\n",full_stack(s));
pop_sqstack(s);
printf("判空:%d\n",empty_stack(s));
return 0;
}
#define N 10
typedef int datatype;
typedef struct
{
datatype data[N];
int top;
}sqstack;
sqstack *creat_empty_sqstack()
{
sqstack *s;
s=(sqstack *)malloc(sizeof(sqstack));
s->top=-1; //-1表示空栈
return s;
}
int empty_stack(sqstack *s)
{
return -1==s->top;
}
int full_stack(sqstack *s)
{
return N-1==(*s).top;
}
void clear_stack(sqstack *s)
{
if(empty_stack(s))
{
printf("此栈已是空栈");
}
else
{
s->top=-1;
printf("清空成功!\n");
}
}
int lenth_stack(sqstack *s)
{
return s->top+1;
}
void push_stack(sqstack *s,datatype x)
{
if(full_stack(s))
{
printf("此栈已满!\n");
}
else
{
s->top=s->top+1;
if(N-1!=s->top)
{
s->data[s->top]=x;
printf("插入成功:%d\n",s->data[s->top]);
}
}
}
datatype pop_sqstack(sqstack *s)
{
if(empty_stack(s))
{
printf("空栈\n");
}
else
{
s->data[s->top]=0;
s->top=s->top-1;
}
}
datatype get_top(sqstack *s)
{
}
int main (int argc,char *argv[])
{
in
sqstack *s;
s=creat_empty_sqstack();
printf("判空:%d\n",empty_stack(s));
push_stack(s,200);
push_stack(s,400);
printf("lenth:%d\n",lenth_stack(s));
pop_sqstack(s);
printf("lenth:%d\n",lenth_stack(s));
printf("判满:%d\n",full_stack(s));
pop_sqstack(s);
printf("判空:%d\n",empty_stack(s));
return 0;
}
- 数据结构--栈的操作
- 数据结构栈操作
- 数据结构 -- 栈的操作
- 数据结构----栈的操作
- 数据结构-栈操作算法
- 数据结构栈的操作
- 数据结构栈的操作
- 数据结构栈操作
- 数据结构-栈的操作
- 【数据结构】链式栈的操作
- 【数据结构】 栈的基本操作
- 数据结构栈的基本操作
- 数据结构---队栈操作(Python)
- 栈的基本操作-数据结构
- 【数据结构】栈的基本操作
- [数据结构]栈的基本操作
- 《数据结构》 栈代码操作集合
- 数据结构--栈的基本操作
- 为什么插入数据普通PC比服务器更快?
- Eclipse快捷键 10个最有用的快捷键
- win7(64)未在本地计算机上注册 Microsoft.Jet.OLEDB.4.0 提供程序
- amcharts _ 2.7.6 实现动态数据展现
- 元芳体走红并非简单恶搞 体现了公众渴望表达的欲望
- 数据结构栈操作
- Windows Hook机制
- 多线程断点续传后台下载
- Mysql启动停止
- photoshop不自动刷新的问题
- 数据结构-队列操作
- SQLServer和Oracle的常用函数对比
- Excel 中使用数据透视表 Pivot Table
- 原谅你,是换来你放肆的资本:伤感日志