主题:帮我改一下程序,各位高手!!小猪在此万分感激啊!!
#include"stdio.h"
#include"malloc.h"
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct stack
{
int stacksize;
int *bottom;
int *top;
}sqstack;
void initstack(sqstack &s);
int push(sqstack &s,int e);
int pop(sqstack &s,int e);
void init_Stack(sqstack &s)
{
s.bottom=(sqstack*)malloc(STACK_INIT_SIZE)*sizeof(struct stack);
s.top=s.bottom;
s.stack=STACK_INIT_SIZE;
}
int push(sqstack &s,int e)
{
if(s.top-s.bottom>=s.stacksize)
{
s.bottom=(sqstack*)realloc(s.bottom,(s.stacksize+STACKINCREMENT)*sizeof(struct stack));
s.top=s.bottom+s.stacksize;
s.stacksize+=STACKINCREMENT;
}
*s.top++=e;
return s;
}
int pop(sqstack &s,int *e)
{
if(s.top==s.bottom)
return (0);
else
e=*-s.top;
return s;
}
void main()
{
int i=12345;
while(i)
{
int i;
int push(&s,i%8);
}
while(!s.stacksize)
{
int oct;
oct*=10;
oct+=pop(sqstack);
}
}
该程序的功能是将十进知数12345化成八进制数
#include"malloc.h"
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct stack
{
int stacksize;
int *bottom;
int *top;
}sqstack;
void initstack(sqstack &s);
int push(sqstack &s,int e);
int pop(sqstack &s,int e);
void init_Stack(sqstack &s)
{
s.bottom=(sqstack*)malloc(STACK_INIT_SIZE)*sizeof(struct stack);
s.top=s.bottom;
s.stack=STACK_INIT_SIZE;
}
int push(sqstack &s,int e)
{
if(s.top-s.bottom>=s.stacksize)
{
s.bottom=(sqstack*)realloc(s.bottom,(s.stacksize+STACKINCREMENT)*sizeof(struct stack));
s.top=s.bottom+s.stacksize;
s.stacksize+=STACKINCREMENT;
}
*s.top++=e;
return s;
}
int pop(sqstack &s,int *e)
{
if(s.top==s.bottom)
return (0);
else
e=*-s.top;
return s;
}
void main()
{
int i=12345;
while(i)
{
int i;
int push(&s,i%8);
}
while(!s.stacksize)
{
int oct;
oct*=10;
oct+=pop(sqstack);
}
}
该程序的功能是将十进知数12345化成八进制数