⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.cpp

📁 栈的应用(1)数制转换
💻 CPP
字号:
#include"Stack.h"
#include<iostream.h>
#include<stdlib.h>
status InitSqStack(SqStack &s)
{
	s.base =(ElementType*)malloc(sizeof(ElementType)*STACKINITSIZE);
	if(!s.base ) return 0;
	s.top=s.base;
	s.stacksize =STACKINITSIZE;
	return 1;

}

status DestroySqStack(SqStack &s)
{
	if(s.base )
	free(s.base );
	s.base =NULL;
	s.top=NULL;
	s.stacksize =0;
	return 1;
}
status ClearSqStack(SqStack &s)
{

	s.top=s.base ;
	return 1;
}

status IsSqStackEmpty(SqStack &s)
{
	if(s.top==s.base )
		return 1;
	else
		return 0;


}
status IsSqStackFull(SqStack &s)
{

	if(s.top>=s.base+STACKINITSIZE )
		return 1;
	else
		return 0;


}


int SqStackLength(SqStack &s)
{
	return s.top-s.base ;

}

status GetSqStackTop(SqStack &s,ElementType &e)
{
	if(s.top >s.base )
		{e=*(s.top -1);
			return 1;
		}
	else
		return 0;

}

status Push(SqStack &s,ElementType e)
{
	if(s.top<s.base + STACKINITSIZE)
		{*s.top =e;
		s.top=s.top +1;
		return 1;

		}
	else
		return 0;
	


}
status Pop(SqStack &s,ElementType &e)

{
	if(s.top>s.base )
		{
		s.top=s.top -1;
			e =*s.top;
		return 1;

		}
	else
		return 0;
	

}


status PrintSqStack(SqStack &s)
{
	ElementType *p;
	for(p=s.base ;p<s.base +STACKINITSIZE;p++)
	cout<<*p<<endl;
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -