- 博客(0)
- 资源 (3)
- 收藏
- 关注
数据结构课程设计(翻译标准C版本)
# include<stdio.h>
# define STACK_INIT_SIZE 100
# define STACKINCREMENT 10
typedef int SElemType;
struct SqStack{
SElemType * base;
SElemType * top;
int stacksize;
int Length;
};
struct SqStack S;
SElemType * e;
void InitStack ()
{
S.base=(SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));
if(!S.base) printf("OVER\n");
else
{
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
S.Length=0;
printf("OK\n");
}
}
void DestroyStack ()
{
free(S.base);
printf("OK\n");
}
void ClearStack ()
{
free(S.base);
S.top=S.base;
printf("OK\n");
}
void StackEmpty ()
{
if(S.top==S.base) printf("TRUE\n");
else printf("FALSE\n");
}
void StackLength ()
{
printf("%d\n",S.Length);
}
void GetTop ()
{
if(S.top==S.base) printf("EORRO");
else
{
printf("%d\n",*(S.top-1));
}
}
void Push ()
{
scanf("%d",S.top);
*S.top++;
S.Length++;
printf("OK\n");
}
void Pop ()
{
if(S.top==S.base)
{
printf("NULL\n");
}
else
{
S.Length--;
S.top--;
printf("OK\n");
}
}
void kTraverse ()
{
if (S.top=S.base)
{
printf("STACK NULL");
}
else
{
e=S.base;
while (e<S.top)
{
printf("%d ",*e);
e++;
}
printf("\n");
}
}
void main()
{}
2010-12-07
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人