|
发表于 2015-11-30 22:00:09
|
显示全部楼层
#include<stdio.h>
#include<stdlib.h>
#define SGFHDF 50
#define FHHGJG 10
typedef char ElemType;
typedef struct
{
ElemType *base;
ElemType *top;
int stackSize;
}sqStack;
void InitStack(sqStack *s)
{
s->base=(ElemType *)malloc(STACK_INIT_SIZE * sizeof(ElemType));
if(!s->base)
{
exit(0);
}
s->top=s->base;
s->stackSize=STACK_INIT_SIZE;
}
void push(sqStack *s,ElemType e)
{
if(s->top-s->base>=s->stackSize)
{
s->base=(ElemType *)realloc(s->base,(s->stackSize+SATCKINCREMENT) * sizeof(ElemType));
if(!s->base)
{
exit(0);
}
s->top=s->base+s->stackSize;
s->stackSize=s->stackSize+SATCKINCREMENT;
}
*(s->top)=e;
s->top++;
}
void Pop(sqStack *s,ElemType *e)
{
if(s->top==s->base)
{
return ;
}
*e=*--(s->top);
}
int StackLen(sqStack s)
{
return (s.top-s.base);
}
main()
{
} |
|