ch3_sstack.c
来自「本人讲授数据结构课程时的所写的示例程序」· C语言 代码 · 共 63 行
C
63 行
/*
栈的顺序实现
author: kk.h
date: 2006.9
http://www.cocoon.org.cn
*/
#include "stdio.h"
#define StackSize 100
typedef int ElemType;
typedef struct {
ElemType elem[StackSize];
int top;
}SqStack;
InitStack(SqStack *pS)
{
pS->top=0; /* top指向栈顶的上一个元素 */
}
int Push(SqStack *pS,ElemType e)
{
if (pS->top==StackSize-1) /* 栈满 */
return 0;
pS->elem[pS->top]=e;
pS->top=pS->top+1;
return 1;
}
int Pop(SqStack *pS,ElemType* pe)
{
if (pS->top==0) /* 栈空 */
return 0;
pS->top = pS->top - 1;
*pe = pS->elem[pS->top];
return 1;
}
main()
{
SqStack S;
ElemType e;
int N;
InitStack(&S);
N=1348;
while(N){
e = N % 8;
Push(&S,e);
N = N/8;
}
while(Pop(&S,&e)){
printf("%d",e);
}
getch();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?