/* 以下程序实现的功能为对于输入的任意一个非负十进制整数,打印输出与其等值的八进制数 */
最后main函数里要填什么?
#include<string.h>
#include<ctype.h>
#include<malloc.h>
#include<limits.h>
#include<stdio.h>
#include<stdlib.h>
#include<io.h>
#include<process.h> /* exit() */
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int Boolean;
typedef int SElemType;
/*栈的顺序存储表示 */
#define STACK_INIT_SIZE 10
#define STACKINCREMENT 2
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize; //填写语句
}SqStack;
Status InitStack(SqStack *S) //初始化顺序栈
{
(*S).base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
if(!(*S).base) exit(OVERFLOW);
(*S).top=(*S).base;
(*S).stacksize=STACK_INIT_SIZE;
return OK;
}
Status DestroyStack(SqStack *S)
{
free((*S).base);
(*S).base=NULL;
(*S).top=NULL;
(*S).stacksize=0;
return OK;
}
Status ClearStack(SqStack *S)
{
S->top = S->base; //填写一条语句
return OK;
}
Status StackEmpty(SqStack S)
{
if(S.top==S.base||S.top<S.base) //括号内补充完整
return TRUE;
else
return FALSE;
}
int StackLength(SqStack S)
{
return S.top-S.base;
}
Status GetTop(SqStack S,SElemType *e)
{
if(S.top>S.base)
{
*e=*(S.top-1);
return OK;
}
else
return ERROR;
}
Status Push(SqStack *S,SElemType e)
{
if((*S).top-(*S).base >= (*S).stacksize) //补充完整判断条件表达式
{
(*S).base = (SElemType *)realloc ((*S).base,((*S).stacksize + STACKINCREMENT)*sizeof(SElemType)); //填写一条语句
if(!(*S).base)
exit(OVERFLOW);
(*S).top= (*S).base + (*S).stacksize;
(*S).stacksize +=STACKINCREMENT; //填写两条语句
}
*((*S).top)++=e;
return OK;
}
Status Pop(SqStack *S,SElemType *e)
{
if((*S).top==(*S).base ) //补充完整判断条件表达式
return ERROR;
*e=*--(*S).top;
return OK;
}
void conversion() /* 算法3.1 */
{
SqStack s;
unsigned n;
SElemType e;
InitStack(&s);
printf("n(>=0)=");
scanf("%u",&n);
while(n)
{
Push(&s,n%8); //填写一条语句
n=n/8;
}
while(!StackEmpty(s))
{
Pop(&s,e); //填写一条语句
printf("%d",e);
}
printf("\n");
}
main()
{
//填写一条语句
getch();
}