农村古墓特征:C语言,数据结构,有一点小问题

来源:百度文库 编辑:高考问答 时间:2024/04/29 04:03:35
//数制转换
#define STACK_INIT_SIZE 100 //存储空间初始分配量
#define STACKINCREMENT 10 //存储空间分配增量
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status ;
typedef int SElemType ;
typedef int ElemType ;
typedef struct
{
SElemType *base ; //在栈构造之前和销毁之后,base的值为NULL
SElemType *top ; //站顶指针
int stacksize ; //当前已分配的存储空间,已元素为单位
}SqStack ;
#include <stdio.h>
#include <malloc.h>
#include <process.h>
//-----------------------------------------------------------------------------------------------
Status InitStack ( SqStack &S ) //构造一个空栈S
{
S.base = (SElemType * ) malloc ( STACK_INIT_SIZE * sizeof ( ElemType )) ;
if ( !S.base )
exit ( OVERFLOW ) ; //存储空间失败
S.top = S.base ;
S.stacksize = STACK_INIT_SIZE ;
return OK ;
}//InitStack
//-----------------------------------------------------------------------------------------------
Status StackEmpty ( SqStack S ) //判断S栈是否为空
{
if ( S.base == S.top )
return TRUE ;
else
return FALSE ;
}//StackEmpty
//-----------------------------------------------------------------------------------------------
Status Push ( SqStack &S , SElemType e ) //插入元素e为新的栈顶元素
{
if ( S.top - S.base >= S.stacksize ) //栈满,追加存储空间
{
S.base = ( ElemType * ) realloc ( S.base , ( S.stacksize + STACKINCREMENT ) * sizeof ( ElemType )) ;
if ( !S.base )
exit ( OVERFLOW ) ; //存储分配失败
S.top = S.base + S.stacksize ;
S.stacksize += STACKINCREMENT ;
}
*S.top++ = e ;
return OK ;
}//Push
//-----------------------------------------------------------------------------------------------
Status Pop ( SqStack &S , SElemType &e )
//若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK,否则返回ERROR
{
if ( S.top == S.base )
return ERROR ;
e = * --S.top ;
return OK ;
}//Pop
//-----------------------------------------------------------------------------------------------
void conversion( int pre_num , int convert_number )
{
*********************************
InitStack ( S ) ; //构造空栈
while ( pre_num )
{
Push ( S , pre_num % 8 ) ;
pre_num = pre_num / 8 ;
}
*******************************
while ( !StackEmpty ( S ) )
{
Pop ( S , e ) ;
printf ( "%d" , e ) ;
}
}
星号的下边1行有错误
部分程序省略

您在使用S之前都没定义......
要么在conversion函数中增加参数,要么有一个全局变量。