求高手相助啊 运行时出现错误 关闭
2010-08-20 13:06
211 查看
/*************************************顺序栈存储结构及常见操作************************************/
#ifndef _seqstack_h
#define _seqstack_h
#include <stdlib.h>//基本库函数
#include <stdio.h>
#define STACKMINSIZE 10//顺序栈存储空间长度的最小值
typedef int StackDT;
class SeqStack //顺序栈存储结构类型定义
{public:
StackDT* base;
int stacksize;
int top;
void StackInitialize(SeqStack ps,int nsize);//初始化
int StackLen(SeqStack s);//求栈长度
bool StackEmpty(SeqStack s);//判断栈是否为空
bool StackFull(SeqStack s);//判断栈是否为满
bool push(SeqStack ps,StackDT d);//入栈
bool pop(SeqStack ps,StackDT pd);//出栈
bool StackGetTop(SeqStack s,StackDT pd);//获取栈顶元素
bool StackPutTop(SeqStack s,StackDT d);//写栈顶元素
void StackClear(SeqStack ps);//清空栈
void StackDestroy(SeqStack s);//销毁栈
};
void SeqStack::StackInitialize(SeqStack ps,int nsize)//初始化
{
if (nsize<STACKMINSIZE)
nsize=STACKMINSIZE;
ps.stacksize=nsize;
ps.base=(StackDT*)malloc(ps.stacksize*sizeof(StackDT));
if (!ps.base)
exit(EXIT_FAILURE);
ps.top=-1;
}
int SeqStack::StackLen(SeqStack s)//求栈长度
{
return s.top+1;
}
bool SeqStack::StackEmpty(SeqStack s)//判断栈是否为空
{
return -1==s.top?true:false;
}
bool SeqStack::StackFull(SeqStack s)//判断栈是否为满
{
return s.stacksize-1<=s.top?true:false;
}
bool SeqStack::push(SeqStack ps,StackDT d)//入栈
{
bool flg=true;
if (StackFull(ps))
{flg=false;
}
else
{ps.base[++ps.top]=d;
}
return flg;
}
bool SeqStack::pop(SeqStack ps,StackDT pd)//出栈
{
bool flg=true;
if (StackEmpty(ps))
{flg=false;
}
else
{pd=ps.base[ps.top--];
}
return flg;
}
bool SeqStack::StackGetTop(SeqStack s,StackDT pd)//获取栈顶元素
{ bool flg=true;
if (StackEmpty(s))
{flg=false;
}
else
{pd=s.base[s.top];
}
return flg;
}
bool SeqStack::StackPutTop(SeqStack s,StackDT d)//写栈顶元素
{
bool flg=true;
if (StackEmpty(s))
{flg=false;
}
else
{s.base[s.top]=d;
}
return flg;
}
void SeqStack::StackClear(SeqStack ps)//清空栈
{
ps.top=-1;
}
void SeqStack::StackDestroy(SeqStack s)//销毁栈
{
free(s.base);
}
#define N 10
void main()
{int i;
StackDT d,a
={0,1,2,3,4,5,6,7,8,9};
SeqStack stack;
stack.StackInitialize(stack,N);
printf("/npush:/n");
for(i=0;i<N;i++)
{
printf("%3d",a[i]);
stack.push(stack,a[i]);
}
printf("/nstack is %s",stack.StackFull(stack)? "full":"not full");
printf("stacklen=%d",stack.StackLen(stack));
printf("/npop:/n");
while (!stack.StackEmpty(stack))
{stack.pop(stack,d);
printf("%3d",d);
}
printf("/nstack is %s/n",stack.StackEmpty(stack)?"empty":"not empty");
stack.StackDestroy(stack);
}
#endif
#ifndef _seqstack_h
#define _seqstack_h
#include <stdlib.h>//基本库函数
#include <stdio.h>
#define STACKMINSIZE 10//顺序栈存储空间长度的最小值
typedef int StackDT;
class SeqStack //顺序栈存储结构类型定义
{public:
StackDT* base;
int stacksize;
int top;
void StackInitialize(SeqStack ps,int nsize);//初始化
int StackLen(SeqStack s);//求栈长度
bool StackEmpty(SeqStack s);//判断栈是否为空
bool StackFull(SeqStack s);//判断栈是否为满
bool push(SeqStack ps,StackDT d);//入栈
bool pop(SeqStack ps,StackDT pd);//出栈
bool StackGetTop(SeqStack s,StackDT pd);//获取栈顶元素
bool StackPutTop(SeqStack s,StackDT d);//写栈顶元素
void StackClear(SeqStack ps);//清空栈
void StackDestroy(SeqStack s);//销毁栈
};
void SeqStack::StackInitialize(SeqStack ps,int nsize)//初始化
{
if (nsize<STACKMINSIZE)
nsize=STACKMINSIZE;
ps.stacksize=nsize;
ps.base=(StackDT*)malloc(ps.stacksize*sizeof(StackDT));
if (!ps.base)
exit(EXIT_FAILURE);
ps.top=-1;
}
int SeqStack::StackLen(SeqStack s)//求栈长度
{
return s.top+1;
}
bool SeqStack::StackEmpty(SeqStack s)//判断栈是否为空
{
return -1==s.top?true:false;
}
bool SeqStack::StackFull(SeqStack s)//判断栈是否为满
{
return s.stacksize-1<=s.top?true:false;
}
bool SeqStack::push(SeqStack ps,StackDT d)//入栈
{
bool flg=true;
if (StackFull(ps))
{flg=false;
}
else
{ps.base[++ps.top]=d;
}
return flg;
}
bool SeqStack::pop(SeqStack ps,StackDT pd)//出栈
{
bool flg=true;
if (StackEmpty(ps))
{flg=false;
}
else
{pd=ps.base[ps.top--];
}
return flg;
}
bool SeqStack::StackGetTop(SeqStack s,StackDT pd)//获取栈顶元素
{ bool flg=true;
if (StackEmpty(s))
{flg=false;
}
else
{pd=s.base[s.top];
}
return flg;
}
bool SeqStack::StackPutTop(SeqStack s,StackDT d)//写栈顶元素
{
bool flg=true;
if (StackEmpty(s))
{flg=false;
}
else
{s.base[s.top]=d;
}
return flg;
}
void SeqStack::StackClear(SeqStack ps)//清空栈
{
ps.top=-1;
}
void SeqStack::StackDestroy(SeqStack s)//销毁栈
{
free(s.base);
}
#define N 10
void main()
{int i;
StackDT d,a
={0,1,2,3,4,5,6,7,8,9};
SeqStack stack;
stack.StackInitialize(stack,N);
printf("/npush:/n");
for(i=0;i<N;i++)
{
printf("%3d",a[i]);
stack.push(stack,a[i]);
}
printf("/nstack is %s",stack.StackFull(stack)? "full":"not full");
printf("stacklen=%d",stack.StackLen(stack));
printf("/npop:/n");
while (!stack.StackEmpty(stack))
{stack.pop(stack,d);
printf("%3d",d);
}
printf("/nstack is %s/n",stack.StackEmpty(stack)?"empty":"not empty");
stack.StackDestroy(stack);
}
#endif
相关文章推荐
- 在Linux系统里运行shutdown.sh命令关闭Tomcat时出现错误提示
- JavaScript在IE下设置innerHTML时出现"未知的运行时错误"
- Android studio 出现java.lang.NoClassDefFoundError错误的一种解决方案 5.0以下机型无法运行应用报错
- c语言结构体指针运行出现错误
- 运行EFDC出现这样的错误:forrt1:severe<157>:Program Exception-access violation
- 运行PHP出现No input file specified错误的解决办法
- VB6 关闭时出现“VB6.EXE - 应用程序错误”解决办法
- Python程序编译运行出现错误:IndentationError: unindent does not match any outer indentation level
- 4000 运行Discuz! X2出现“Notice: Undefined index”错误的解决办法
- 【Qt5 for VS】关于出现 Qt platform plugin "windows" 运行错误的解决方案
- AndroidStudio运行项目出现Unsupported method: AndroidProject.getPluginGeneration()错误解决办法
- Java运行时环境初始化时出现错误,你可能需要重新安装Flash(CS5)
- C#调用WebService出现“基础连接已经关闭:接收时发生错误”错误
- 【TensorBoard】运行TensorBoard出现的错误汇总及相关的解决方案
- 【已解决】Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level
- Tk1上ROS与Arduino通信,运行“Hello World”时,出现的错误(Unable to sync with device; possible link problem or )及解决方法
- ubuntu上运行命令sudo apt-get dist-upgrade,出现错误gzip: stdout: No space left on device
- 运行java.exe 出现Registry key 'Software/JavaSoft/Java Runtime Environment/CurrentVersion'错误的解决。
- 黄聪:C# 出现“已关闭 Safe handle”的错误
- excel2010加载matlab的exlink出现“运行时错误429,activex部件不能创建对象”的解决办法